test: fix EventCollector double-free race in sse client tests#542
Merged
Conversation
kinyoklion
approved these changes
May 29, 2026
Member
kinyoklion
left a comment
There was a problem hiding this comment.
The OnConnectHookInvokedBeforeRequest and OnConnectHookInvokedOnEachReconnect tests violate the invariant that any state captured must be declared before the runner, but in a way that is harmless.
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.
Summary
ASAN occasionally caught a double-free in
ClientTest.OnConnectHookSeesPreviousMutations(and potentially other sse-client tests) on CI. We couldn't reproduce locally — even on Linux — and it appears to fire only rarely on CI.The fixture declared
IoContextRunnerbeforeEventCollector, so on scope exit the collector was destroyed first while the io_context worker could still be running a receiver callback that pushed into the collector's vector. Swap declaration order so the collector outlives the runner —~IoContextRunnerjoins the worker, so once it returns no callback can race the collector's destructor.Test plan
Note
Low Risk
Test-only declaration order and documentation; no runtime library or API changes.
Overview
Fixes a flaky ASAN double-free in SSE client integration tests by correcting stack object destruction order in test fixtures.
Tests previously declared
IoContextRunnerbeforeEventCollector, so on scope exit the collector was destroyed while the backgroundio_contextthread could still run receiver lambdas that write into it. The change declaresEventCollectorfirst, thenIoContextRunner, so~IoContextRunnerjoins the worker before the collector is torn down. A short comment onIoContextRunnerdocuments this requirement for future tests.No production SSE client behavior changes—test-only lifetime fix applied across the affected
ClientTestcases inclient_test.cpp.Reviewed by Cursor Bugbot for commit 0b6fbae. Bugbot is set up for automated code reviews on this repo. Configure here.