StartClient leaks a PostgreSQL connection pool on every instance connect
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- Nửa ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Go
- Star
- 971
- Fork
- 519
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Không có hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của evolution-foundation/evolution-go
-
/user/info and /user/avatar hang for 75s when number is a phone numberCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
evolution-foundation/evolution-go#223 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
evolution-foundation/evolution-go#193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
evolution-foundation/evolution-go#104 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
evolution-foundation/evolution-go#101 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
POST /group/participant always returns 400 "participants is required and cannot be empty" (wrong validation middleware on route)Có thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
evolution-foundation/evolution-go#97 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của evolution-foundation/evolution-go
Issue tương tự
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
valkey-io/valkey-operator#610 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
-
WriterSetTimes: the UTIME_NOW check fails when the kernel uses its coarse clockCó thể đã có người làm @JakeChampion đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
JakeChampion/lang#14224 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
docs(reference): pi stream-filter bullet says tool_execution_update passes through unchangedĐang mởagent-butler-finding bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
jordansmall/spindrift#6391 ·
Maintainer thường phản hồi trong vòng 1 ngày