Postgres connection leak: StartClient creates a new sqlstore.Container per (re)connect and never closes it
Maintainer thường phản hồi trong vòng 5 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Đọc pkg/whatsmeow/service/whatsmeow.go, tập trung vào StartClient ở dòng 322 và đường dẫn RestartInstance -> StartInstance ở dòng 237. Tái hiện các lần kết nối lại lặp đi lặp lại hoặc kiểm tra vòng đời của container, sau đó xác minh rằng các lần kết nối lại không còn để các pool database/sql ở trạng thái mở hoặc tích lũy các backend PostgreSQL.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
StartClient builds a fresh sqlstore.Container at pkg/whatsmeow/service/whatsmeow.go:322 on every call. The container is a local variable and is never closed — there is no container.Close() anywhere in the file. Each call therefore leaks a whole database/sql pool.
This is not limited to the first connect: RestartInstance ends in Starting fresh instance -> StartInstance -> StartClient (whatsmeow.go:237), and WhatsApp drops the websocket on its own several times a day (Got 503 stream error, failed to read frame header: EOF), each drop triggering Disconnected detected, restarting instance.
Measured
v0.7.2, Postgres 15.6, a single connected instance, nobody using the panel: 17 backends on evogo_auth accumulated over 18h, with zero GET /instance/qr in the window.
- Connections appear in pairs — the
MaxIdleConnsdefault ofdatabase/sql— and theirbackend_starttimestamps match the restart lines in the log to the second. - 6 reconnects in 18h, so ~16 connections/day:
max_connections=100exhausted in ~6 days. We hit that twice. - Once exhausted, QR generation stops and
sendTextreturns500. The server then reconnects in a loop (11Starting fresh instancein 80 seconds), burning whatever is left, so the saturation looks sudden. - It scales with instance count — ten numbers would saturate in half a day.
Requesting QR is just another path into the same StartClient, so /instance/qr makes it faster but is not the cause.
Suggested fix
Create the container once per process (the DSN never changes) and reuse it, or keep a reference per instance and Close() the old one before starting fresh.
Workaround
For anyone hitting this before a fix lands:
ALTER DATABASE evogo_auth SET idle_session_timeout = '1h';
Postgres then reaps the orphaned pools. Safe for live sessions: credentials live in the whatsmeow_* rows, not in the TCP connection, and pgx discards a dead connection silently before use. Took us from 17 backends to 6 with no disconnect and no re-pairing.
- Ngôn ngữ chính
- Go
- Star
- 890
- Fork
- 473
- 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
-
Độ 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 5 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 5 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 5 ngày
-
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 5 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
evolution-foundation/evolution-go#204 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 5 ngày
Tất cả issue của evolution-foundation/evolution-go
Issue tương tự
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
open-telemetry/opentelemetry-go-compile-instrumentation#1417 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
agent-research-finding agent-research-recommend chore ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
jordansmall/spindrift#4068 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Type/Task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
OpenNSW/nsw-srilanka#537 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
security
Độ khó 2/5 1-2 ngày Mức phù hợp với người mới 62/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày