Skip to content

fix(server): close Consume race on returnError and stopForLoop teardown#97

Open
miotte wants to merge 1 commit into
mainfrom
miotte-pr6
Open

fix(server): close Consume race on returnError and stopForLoop teardown#97
miotte wants to merge 1 commit into
mainfrom
miotte-pr6

Conversation

@miotte

@miotte miotte commented May 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #95

Wait for the sender and Subscribe goroutines before Consume returns, and make stopForLoop carry the error so the main path stays the sole writer of returnError. Defers are ordered so the channels close with no writers left.

Consume spawned sender and Subscribe goroutines that wrote to returnError
and read stopForLoop through heap-escaped pointers, then returned without
waiting for them. The goroutines kept running past Consume's return,
racing against its writes to returnError and its deferred close+nil of
stopForLoop.

Wait for those goroutines before returning, and make stopForLoop carry
the error itself so main is the sole writer of returnError. The defers
are ordered so loopCancel signals first, wg.Wait drains the goroutines
next, and the channels close last with no writers left.

Signed-off-by: Michael Otteni <MichaelGOtteni@gmail.com>
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.

Race in server.Consume between teardown and spawned goroutines

1 participant