StartClient leaks a PostgreSQL connection pool on every instance connect
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 45/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Go
- Estrellas
- 929
- Forks
- 499
- Merge medio
- 5 min
- PR fusionados (30 d)
- 1
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de evolution-foundation/evolution-go
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
evolution-foundation/evolution-go#193 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
evolution-foundation/evolution-go#104 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
evolution-foundation/evolution-go#101 ·
Los mantenedores suelen responder en 1 día
-
POST /group/participant always returns 400 "participants is required and cannot be empty" (wrong validation middleware on route)Posiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
evolution-foundation/evolution-go#97 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
evolution-foundation/evolution-go#219 ·
Los mantenedores suelen responder en 1 día
Todos los issues de evolution-foundation/evolution-go
Issues similares
-
Realtime: ASR EOU language tags leak into the LLM conversation (unintended reply-language switching)Posiblemente ocupada @nexxtmobile la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
effort:high model:sonnet phase:3 type:docs
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
OffchainLabs/nitro#4771 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
BurntSushi/toml#530 ·