Repository navigation
Conversation
Several frames a remote server may legitimately send crashed the
Slipstream.Connection process with a FunctionClauseError:
* Ping and pong frames. Mint.WebSocket decodes these as `{:ping, data}`
and `{:pong, data}`, but `Impl.decode_message/2` only matched the bare
`:ping`/`:pong` atoms, so the existing PingReceived/PongReceived
handling (and the automatic pong reply) was unreachable.
* Invalid frames, e.g. a text frame which is not valid UTF-8. Mint.WebSocket
includes `{:error, reason}` entries in the decoded frame list. These now
fail the connection as RFC 6455 requires, with a ChannelClosed reason of
`{:invalid_frame, reason}`.
* Replies with a status other than "ok" or "error". Phoenix allows any atom
status (e.g. `{:reply, {:accepted, %{}}, socket}`). These are now given to
`c:Slipstream.handle_reply/3` with the status as a string, so no atoms are
created from server input.
* A `phx_error` whose ref is not a tracked join ref hit a
`true = State.join_ref?(...)` assertion. It is now ignored.
Because the client process does not monitor the connection process, each
of these crashes left the client believing it was still connected with no
`handle_disconnect/2` and no reconnect.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
|
Adding This line of PRs looks pretty good but there is a CI failure from a compiler warning on Elixir 1.20 as mentioned in #89 which needs a fix. I'll give these PRs a closer look when I get a chance |
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.
Problem
Several frames a server can legitimately send crash the
Slipstream.Connectionprocess with aFunctionClauseErrororMatchError:{:ping, data}/{:pong, data}, butImpl.decode_message/2only matches the bare atoms:ping/:pong(lib/slipstream/connection/impl.ex:125). The existingPingReceived/PongReceivedhandling, including the automatic pong reply, is therefore unreachable.{:error, reason}entries in the decoded frame list, and nothing matches them."ok"/"error". Phoenix allows any atom status ({:reply, :accepted, socket},{:reply, {:queued, %{}}, socket}), butReplyReceived.to_reply/1only matches those two (lib/slipstream/events/reply_received.ex:11).phx_errorwhose ref isn't a tracked join ref hitstrue = State.join_ref?(state, ref)(lib/slipstream/events.ex:121).The client process doesn't monitor the connection process, so after any of these crashes
handle_disconnect/2is never called and the client never reconnects.Reproduction
A Phoenix channel that replies with a custom status:
Pushing
"work"from a Slipstream client kills the connection process:A server that sends a WebSocket ping fails the same way in
Slipstream.Connection.Impl.decode_message/2with{:ping, "..."}.Changes
handle_disconnect/2with{:invalid_frame, reason}.handle_reply/3as strings,"accepted"or{"queued", response}, so no atoms are created from server input. Thereply()type and its docs are updated.phx_errorfor an unknown join ref is ignored.Compatibility
reply()type is wider. Replies with other statuses used to crash the connection, so no working code depends on 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. Claude reproduced these crashes against
mainwith the fake server above and wrote this change and its tests.