Repository navigation
fix: ignore callbacks from a signal socket that was already replaced - #1211
Open
hiroshihorie wants to merge 4 commits into
Open
hiroshihorie wants to merge 4 commits into
hiroshihorie wants to merge 4 commits into
Conversation
A real socket reports its close a few milliseconds after dispose() returns. That report went through the same handler as a live close, so when it landed during the next connect it reset the signal state to disconnected and started a reconnect against a socket that was fine. Each socket's callbacks now carry a generation, bumped on cleanUp() and on every connect, and a callback from an older generation is dropped. The signalReconnect and fullReconnect debug scenarios relied on that late close to trigger the engine's recovery. They now call simulateSignalDrop(), which disposes the socket and raises the disconnect explicitly. The mock socket reports its close after dispose() like the real ones, so the race is reproducible in tests.
…ocket cleanUp() now ignores the close the disposed socket reports afterwards, so callers that relied on that late close to make the engine recover stopped working. The connection checker's reconnect check always reported that no reconnect was attempted, and the disconnectSignalOnResume debug actions never started the resume the server is waiting for. Both now call simulateSignalDrop(), like the signalReconnect and fullReconnect scenarios already do.
…hi/signal-socket-generation
hiroshihorie
marked this pull request as ready for review
October 16, 2026 21:56
hiroshihorie
requested review from
changt,
cloudwebrtc and
xianshijing-lk
as code owners
October 16, 2026 21:56
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
hiroshihorie
added this pull request to stack #1242
October 16, 2026 21:59
_socketGeneration becomes _socketId. The value is compared to decide whether a callback came from the current socket, which an id describes more directly than a generation. No behavior change.
This branch has not been deployed
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.
Stacked on #1208.
Problem
A real socket reports its close a few milliseconds after the SDK disposes it (
websocket/io.dartonDone,websocket/web.dartonClose).SignalClientrouted that report through the same handler as a live server close. If it landed while the next connection was being established, it set the signal state back todisconnectedand the engine, no longer closed, started a reconnect against a healthy socket. The window is small, adisconnect()followed immediately byconnect(), or any full reconnect, but it is real. #1208 makesdisconnect()return sooner, so this is the right time to close it.Fix
onData,onDisposeandonErrorcallbacks carry the generation of the socket they were created for.cleanUp()andconnect()bump the generation. A callback from an older generation is dropped with a log line.signalReconnectandfullReconnectdebug scenarios used to callsignalClient.cleanUp()and rely on the late close to make the engine recover. That path is now dropped by design, so they call a new internalsimulateSignalDrop()which disposes the socket and raises the disconnect explicitly. Same observable behaviour.dispose()with a configurable latency, like the real implementations, so the race is reproducible.Tests
test/core/stale_socket_close_test.dart:signalReconnectdebug scenario still re-opens the signal connection as a resume.Full suite 430 passing.
🤖 Generated with Claude Code
Update: the counter is now
_socketId(ef6abd1), since it only decides whether a callback came from the current socket. Where the description above says generation, it means this id.