Repository navigation
Add a timeout for the WebSocket upgrade response - #88
Merged
Merged
Conversation
Previously, if a server accepted the TCP connection but never responded
to the WebSocket upgrade request, the connection would wait forever. The
heartbeat timer only starts once the upgrade completes. Mint has a
connect timeout, but it only covers opening the TCP/TLS connection.
This change introduces an `upgrade_timeout_msec` option which defaults
to ten seconds (`0` to turn off). When that timeout elapses, the
connection is closed and `c:Slipstream.handle_disconnect/2` is invoked
with `{:error, :upgrade_timeout}`.
This was referenced Sep 10, 2026
|
Just stumbled on this as thousands of our devices on Nerves Hub fell offline after a brief outage and ever came back on, but our MQTT link is still up, which points to NervesHubLink's usage of Slipstream. Would be nice to know where this is at. @the-mikedavis |
|
It would be fantastic to get this merged in. NervesHubLink uses Slipstream, and with one self-hosted platform supporting over 300k devices, covering this gap is important for us. |
joshk
added a commit
to nerves-hub/nerves_hub_link
that referenced
this pull request
Oct 21, 2026
Checking this work against the open Slipstream pull requests turned up
three things it had not actually addressed.
A reply from NervesHub to one of the device's own pushes took the socket
down. Phoenix sends a reply whenever a channel handler returns one, so
any push the device makes can be answered, and `handle_reply/3` had a
single clause for the extensions detach. Everything else raised a
`FunctionClauseError`. This predates the move - the same single clause
was there on Slipstream, which dispatched to it the same way - and was
only latent because NervesHub does not reply to these pushes today.
Verified against a real server before and after.
A reply whose status is neither `ok` nor `error` was reported as an
error, turning a success into a failure. Phoenix lets a channel reply
with any status, so an unknown one is now passed through as it arrived.
A frame Mint cannot read - a reserved opcode, a text frame that is not
valid UTF-8 - arrives as an `{:error, reason}` entry in the frame list
rather than as a decode failure, which is what CuatroElixir/slipstream#93
is about. The generic catch-all was absorbing these; it now has a clause
of its own that says so, and naming it made the catch-all provably
unreachable, so that went rather than gaining a dialyzer ignore.
CuatroElixir/slipstream#88 was implemented but not reachable: the
upgrade timeout was a `Connection` default with nothing passing it from
configuration. It is now `upgrade_timeout_msec`, 10 seconds to match the
upstream default, with `0` to wait forever, and covered end to end
against a listener that accepts the connection and says nothing.
448 tests, credo and dialyzer clean on 1.18.4/OTP 27.3.4 and
1.19.5/OTP 28.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
Author
|
Thanks for the feedback! I'll merge it down and work on cutting the next release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, if a server accepted the TCP connection but never responded to the WebSocket upgrade request, the connection would wait forever. The heartbeat timer only starts once the upgrade completes. Mint has a connect timeout, but it only covers opening the TCP/TLS connection.
This change introduces an
upgrade_timeout_msecoption which defaults to ten seconds (0to turn off). When that timeout elapses, the connection is closed andc:Slipstream.handle_disconnect/2is invoked with{:error, :upgrade_timeout}.Fixes #75