test: fix flaky TestAttachedServer_DeleteEmitsSessionExited#3418
Merged
Conversation
Emit and read a first SSE event to guarantee the handler has subscribed to the event log before calling DeleteSession, avoiding a race where the stream closed with EOF before session_exited was delivered. Assisted-By: Claude
docker-agent
reviewed
Jul 2, 2026
docker-agent
left a comment
Contributor
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The sentinel-event synchronization approach is correct and well-designed. The "hello" event is emitted before DeleteSession is called, providing a deterministic proof that the SSE handler is actively subscribed — eliminating the race that caused intermittent failures. No bugs were introduced by the changed lines.
Sayt-0
approved these changes
Jul 2, 2026
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.
The SSE handler in the attached server flushes response headers before it subscribes to the event log via
StreamEvents. In the test, theHasEventSourceguard was effectively a no-op because the test itself registers the event source — soDeleteSessioncould race ahead and remove the event log before the handler had a chance to subscribe. The stream then closed with a clean EOF and nosession_exitedevent, causing the test to fail intermittently (observed in CI run https://github.com/docker/docker-agent/actions/runs/28590850454/job/84773735898).The fix adds a "hello" sentinel event to the fake event source. The test now reads that event from the SSE stream before calling
DeleteSession, which proves the handler is actively subscribed before the session is torn down. The test then asserts the terminalsession_exitedevent as before.Validated with 100 runs under
-race, the fullpkg/serversuite,go vet, andgolangci-lintwith zero issues.