Skip to content

test: fix EventCollector double-free race in sse client tests#542

Merged
beekld merged 1 commit into
mainfrom
beeklimt/fix-sse-test-eventcollector-race
May 29, 2026
Merged

test: fix EventCollector double-free race in sse client tests#542
beekld merged 1 commit into
mainfrom
beeklimt/fix-sse-test-eventcollector-race

Conversation

@beekld
Copy link
Copy Markdown
Contributor

@beekld beekld commented May 29, 2026

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 IoContextRunner before EventCollector, 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 — ~IoContextRunner joins the worker, so once it returns no callback can race the collector's destructor.

Test plan

  • Full sse-client suite (101 tests, 1 pre-existing skip) green under ASAN locally

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 IoContextRunner before EventCollector, so on scope exit the collector was destroyed while the background io_context thread could still run receiver lambdas that write into it. The change declares EventCollector first, then IoContextRunner, so ~IoContextRunner joins the worker before the collector is torn down. A short comment on IoContextRunner documents this requirement for future tests.

No production SSE client behavior changes—test-only lifetime fix applied across the affected ClientTest cases in client_test.cpp.

Reviewed by Cursor Bugbot for commit 0b6fbae. Bugbot is set up for automated code reviews on this repo. Configure here.

@beekld beekld requested a review from a team as a code owner May 29, 2026 17:06
Copy link
Copy Markdown
Member

@kinyoklion kinyoklion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@beekld beekld merged commit f1e7555 into main May 29, 2026
49 checks passed
@beekld beekld deleted the beeklimt/fix-sse-test-eventcollector-race branch May 29, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants