StartClient leaks a PostgreSQL connection pool on every instance connect
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- Mezza giornata
- Idoneità per principianti
- 45/100
Direzione di ricerca
Start in pkg/whatsmeow/service/whatsmeow.go at the sqlstore.New call inside StartClient, and compare it with the pool settings in pkg/config/config.go, which only apply to the CreateAuthDB and CreateUsersDB handles. Decide whether to share one container across instances or keep one per instance and close it on disconnect or restart. Done when repeated connects and reconnects no longer grow the idle connection count on the auth database.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
StartClient creates a new sqlstore.Container on every call and never closes the previous one, so each instance connection (and each auto-reconnect) leaks a full database/sql connection pool. On a busy server this exhausts PostgreSQL max_connections and the instances stop being able to connect at all.
Reproduced on tag 0.7.2; the code is the same on main.
The leak
pkg/whatsmeow/service/whatsmeow.go, inside StartClient:
container, err = sqlstore.New(context.Background(), "postgres", w.config.PostgresAuthDB, nil)
Two things combine here:
sqlstore.Newopens its own*sql.DB. The pool limits set inpkg/config/config.go(SetMaxOpenConns(25),SetMaxIdleConns(5),SetConnMaxIdleTime(1 * time.Minute)) apply to the handles returned byCreateAuthDB/CreateUsersDB, not to this one.- There is no
container.Close()anywhere in the file — only theclientis kept (inclientPointer). The container goes out of scope, but Go's GC does not close a*sql.DB's connections; they stay open until an explicitClose().
StartClient runs on startup (CONNECT_ON_STARTUP), on every /instance/connect, and on every automatic reconnect — so an instance that keeps dropping (logged out from phone, QR expired) leaks fastest.
Evidence from production
Measured on a server with 22 connected instances out of 33:
66 connections to the auth database — 100% idle, 0 active
oldest: opened 32m20s ago, idle 32m19s ← used once, then abandoned
growth: ~30 connections/hour on top of the 44 the startup opens
The per-connection pattern is a staircase — one group per connection attempt, each idle since the moment it was created. From a fresh start it reaches a 300-connection threshold in about 9 hours.
Because the pools are never reused, terminating the idle connections is safe and reclaims them immediately (verified: 66 → 40, all instances stayed connected, traffic continued within 5 seconds, no database errors) — but that is a workaround, not a fix.
Suggestion
Either create the container once and share it across instances (the DSN is the same for all of them), or keep a reference per instance and Close() it when the instance disconnects or is restarted.
- Lingua principale
- Go
- Stelle
- 939
- Fork
- 505
- Merge medio
- 5m
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di evolution-foundation/evolution-go
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
evolution-foundation/evolution-go#193 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
evolution-foundation/evolution-go#104 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
evolution-foundation/evolution-go#101 ·
I maintainer di solito rispondono entro 1 giorno
-
POST /group/participant always returns 400 "participants is required and cannot be empty" (wrong validation middleware on route)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
evolution-foundation/evolution-go#97 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 20/100
evolution-foundation/evolution-go#219 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di evolution-foundation/evolution-go
Issue simili
-
usage: a custom provider's balance meters ("…%" in the balance path) ignore the Left/Used switchAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
bug iam-service
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
platform-mesh/platform-mesh#425 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
grafana/tempo-operator#1691 ·
I maintainer di solito rispondono entro 1 giorno
-
fix: presentation.go with mcp-table.go: the message for each MCP server comes backForse già presa @mge1512 l’ha presa oggi. Apertabug
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
mark3labs/kit#242 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
slavakurilyak/awesome-ai-agents#827 ·
I maintainer di solito rispondono entro 1 giorno