Issue Description
Stalwart 1.0.3 (8b32686), 3 nodes, PostgreSQL + Patroni through a local HAProxy, Valkey, S3 blobs. connectTimeout 15000, the default.
When the database stops answering but TCP stays up, every database wait on that node blocks. I found no limit in the code and saw none in 20 minutes. The node stops sending mail and refuses logins by hanging. It logs nothing and its health checks stay 200, so nothing shows the fault. Other nodes keep delivering, which hides it further.
Expected Behavior
A database wait that gets no reply ends in a logged error within a bounded time, the node’s queue carries on with other work, and /healthz/ready reports the store isn’t answering.
Actual Behavior
Result, 1 run, 20 minutes frozen:
| Check, frozen node | Result |
|---|---|
| Process | Same PID throughout, no restart |
/healthz/live, /healthz/ready |
200 at every check |
| Log warnings and errors, first 20 min | 0 of 29 lines; 0 on the other nodes too |
| Mail sent by this node | 0 (it delivered before the freeze) |
| Submission | Connects, then hangs at login; my client gave up after 45 s, 4 of 4 |
| Database sockets | ESTABLISHED, last receive growing past 1,100 s |
| Message held with HOLDFOR, ingested here, due during the freeze | Delivered by another node, at +289 s |
| Controls, the other two nodes | 42 of 42 delivered, 0 duplicates |
After the sockets were killed, still frozen: 9 store.postgresql-error at once, so a closed socket is reported. Then 3 new connections, ESTABLISHED with nothing received for 180 s and no further errors, though connectTimeout is 15 s. Submission still timed out.
After the thaw it recovered by itself, same PID: submission in 0.7 s, then 24 of 24 further messages delivered, 20 sent by this node, 0 duplicates.
Reproduction Steps
- Run a node’s database connections through a local proxy. Check every node delivers.
- Freeze the proxy on one node:
pkill -STOP -x haproxy. Sockets stay ESTABLISHED, the kernel still ACKs, no reply comes. - Keep submitting on the other nodes (control). Try a submission on the frozen node, and watch its log,
/healthz/live,/healthz/readyand sockets. - Kill its database sockets while still frozen:
ss -K -tn 'dst 127.0.0.1:5433'. Wait 180 s. - Thaw:
pkill -CONT -x haproxy.
Relevant Log Output
Log, after killing the sockets, trimmed:
2026-11-05T05:33:53Z ERROR PostgreSQL error (store.postgresql-error) reason = "connection closed", causedBy = "crates/store/src/dispatch/store.rs:152", causedBy = "crates/smtp/src/queue/walk.rs:157", ...
2026-11-05T05:33:53Z ERROR PostgreSQL error (store.postgresql-error) reason = "connection closed", causedBy = "crates/store/src/dispatch/store.rs:152", causedBy = "crates/services/src/task_manager/manager.rs:396", ...
2026-11-05T05:33:53Z ERROR PostgreSQL error (store.postgresql-error) listenerId = "submission", localPort = 587, reason = "connection closed", causedBy = "crates/store/src/dispatch/store.rs:44", ...
Stalwart Version
v1.x
Installation Method
Binary (Linux)
Database Backend
PostgreSQL
Blob Storage
S3-compatible
Search Engine
PostgreSQL
Directory Backend
Internal
Additional Context
Limits of this test: it freezes all database access on one node, a stand-in for a hung proxy or peer. It doesn’t show that one hung socket among several stops the queue.
Seen on 1.0.2, not reproduced on 1.0.3: after a database primary was powered off, one node stopped processing its queue for about 9 hours with a single socket stuck. Same PID, no errors, health OK. Killing that socket brought the queue back.
Source as I read it:
store/src/backend/postgres/main.rs:29-50setsconnect_timeoutbut no deadpoolwait,createorrecycletimeout, and no statement or read timeout. deadpool’s defaults are no timeouts. tokio-postgres appliesconnect_timeoutto the socket connect only, not the startup handshake, which would fit the 180 s above.smtp/src/queue/manager.rs:168awaitsprocessinline, so one stuck read holds up that node’s whole queue manager.- TCP keepalive or
tcp_user_timeoutwouldn’t catch this case, since the peer’s kernel still ACKs. It takes a timeout at the application level.
docs/cluster/configuration/load-balancing.md says /healthz/ready is 200 when the node “has its data store open”. http/src/request.rs:707 only checks that a store is configured, so a store that has stopped answering still counts.
We bound this outside Stalwart: TCP timeouts on HAProxy, and a watchdog that restarts Stalwart when a socket to the database has had no reply for 5 minutes.
Possibly related, no shared cause shown: Stalwart 0.16.23: mail delivery stops while messages remain queued, delivery stops while messages remain queued. A stuck database socket would be worth checking next time.
Question: would you consider bounding these waits, with the error logged, and having /healthz/ready turn 503 when the store stops answering? Waiting forever on a database read is a fault in itself, even with the network to blame.
Tested and written with AI help.
I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.
on
I have searched this support forum (open and closed topics) and confirm this is not a duplicate.
on
I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.
on