fix: ignore callbacks from a signal socket that was already replaced - #1211
Draft
hiroshihorie wants to merge 1 commit into
Draft
hiroshihorie wants to merge 1 commit into
hiroshihorie wants to merge 1 commit 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.
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