Repository navigation
Conversation
Closes CuatroElixir#85 Writes to the socket (`Mint.WebSocket.stream_request_body/3` -> `:gen_tcp.send/2` / `:ssl.send/2`) had no timeout. When the peer stops reading (a stalled server, a dead load balancer path, a zero TCP window) the send buffers fill and the write blocks indefinitely. The connection process is then stuck inside the send: it can no longer process the heartbeat tick which would detect the dead connection, the client's `:DOWN`, or any other message, so it never self-heals and its mailbox grows without bound. This adds a `:send_timeout_msec` option (default 30 seconds, `0` to disable) which sets the `:send_timeout` and `:send_timeout_close` transport options. A write which times out closes the socket and the client gets `handle_disconnect/2` with `{:send_failure, reason}`, which reconnects by default. Transport options given explicitly in `:mint_opts` take precedence over these defaults. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@joshk nothing in progress, somehow I'm more busy than I wanted but at least I can share some of my data. I will ask claude to give you data what I gathered from our production, or some summary of it which can be useful. |
|
@joshk thanks for picking this up. Here is what we observed in production, plus a few notes from running the PR locally. What we saw in productionSetup: one long-lived WSS client per node, multiplexing multiple topics. The incident ran Slipstream 1.2.2, Mint 1.9.0, MintWebSocket 1.0.5 and OTP 29.0.2. We have eight memory-watchdog samples from 2026-06-30 and 07-01. In each one, That is the same synchronous-send boundary your test reaches, through TLS rather than plain TCP. A snapshot shows where the process was waiting, not how long that particular call stayed blocked. These were watchdog reports, not confirmed kernel OOM kills. Corrections to #85We filed #85, and a few things in it were overstated:
Since we set a send timeout ourselvesWe run
That is a quiet-run baseline. It is not production evidence that the timeout recovered a stalled send. On OTP-20257 (fixed in 29.0.4, missing Notes from running the PR locallyOn OTP 29.0.5 / Elixir 1.20.4, the focused tests passed 201 consecutive runs with one scheduler ( CI hasn't run on this PR yet. When it does, I expect at least this failure: 0. The lint job will fail to compile on Elixir 1.20. CI runs
Two more suggestions:
— Oliver's Claude & Amp |
Closes #85
Problem
As described in #85, writes to the socket have no timeout. The path is
Impl.push_message/2→Mint.WebSocket.stream_request_body/3→:gen_tcp.send/2/:ssl.send/2, and Mint doesn't set:send_timeout.When the peer stops reading (a stalled server, a dead load balancer path, a zero TCP window), the send buffers fill and the write blocks indefinitely. The connection process is then stuck inside the send. It can't process the heartbeat tick that would detect the dead connection, or the client's
:DOWN, or anything else. It never self-heals, and its mailbox keeps growing.I reproduced this against
mainwith a peer that completes the upgrade and then stops reading::heartbeat_timeoutafter 3 seconds.:prim_inet.send/4viaMint.WebSocket.stream_request_body/3.Changes
Following option (b) from #85:
:send_timeout_msecoption (default30_000,0to disable) sets the:send_timeoutand:send_timeout_closetransport options.handle_disconnect/2with{:send_failure, %Mint.TransportError{reason: :timeout}}, which reconnects by default.:mint_optsstill take precedence, so the existing workaround from Connection can block indefinitely on a stalled send (no send_timeout), defeating heartbeat self-heal and growing the process heap until OOM #85 keeps working unchanged.:sslsockets accept both options, using:ssl.getopts/2on a TLS connection made through Mint.The default of 30 seconds matches the default heartbeat interval, so a stalled write is noticed within about two heartbeat intervals. [Happy to derive it from
:heartbeat_interval_msecinstead if you'd prefer.]Compatibility
0restores the old behaviour.How this was found, and AI use
I found this during a review of Slipstream's memory and timeout behaviour that I did with Claude Code, before I saw #85. Claude reproduced the blocked send against
mainand wrote this change and its tests. [@oliver-kriska offered a PR for #85; I'm happy to defer to theirs if it's already in progress.]