Repository navigation
Conversation
The client process never monitored the Slipstream.Connection process. It
only learned about disconnects from the ChannelClosed event which the
connection process sends before stopping. If the connection process exited
any other way (a crash, being killed, a bug), `handle_disconnect/2` was
never invoked, so the default reconnect never happened and the client sat
"disconnected" forever with `connected?/1` returning false.
The client now monitors the connection process once it is connected
(in `Socket.apply_event/2` for ChannelConnected, which runs in the client
process for both the callback and `await_connect/2` paths). A `:DOWN` for
that monitor is dispatched as a ChannelClosed event with the reason
`{:connection_exited, exit_reason}`. The monitor is removed (and flushed)
when a normal ChannelClosed event is applied so a regular disconnect is
still only reported once.
In test mode the "connection" is the test process, so it is not monitored
and `Slipstream.SocketTest` behaves as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
The client process only learns about a disconnect from the
ChannelClosedevent that the connection process sends just before it stops. If the connection process exits any other way,handle_disconnect/2is never called. The default reconnect never happens, and the client stays disconnected indefinitely:connected?/1returnsfalseand nothing reconnects. For a long-lived client, such as a Nerves device in the field, only restarting the client recovers it.The connection process already monitors the client (
lib/slipstream/connection/state.ex:48), but not the other way round.Reproduction
Changes
Socket.apply_event/2forChannelConnected, which runs in the client process for both the callback and theawait_connect/2paths.use Slipstreamgains ahandle_info/2clause for that monitor's:DOWN, which is dispatched as aChannelClosedwith the reason{:connection_exited, exit_reason}.ChannelClosedthe monitor is removed and flushed, so a regular disconnect is still reported exactly once.Slipstream.SocketTestbehaves as before.Compatibility
handle_disconnect/2can receive a new reason,{:connection_exited, reason}, which is documented.%Slipstream.Socket{}gains achannel_monitorfield.handle_info({:DOWN, ...}, socket)clauses are unaffected: the new clause only matches the socket's own monitor ref.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. While undergoing an adversarial review, Claude found that it was possible for the client to never notice that the connection had died, and wrote this change and its tests.