fix(server): close Consume race on returnError and stopForLoop teardown#97
Open
miotte wants to merge 1 commit into
Open
fix(server): close Consume race on returnError and stopForLoop teardown#97miotte wants to merge 1 commit into
miotte wants to merge 1 commit into
Conversation
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>
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.
Fixes #95
Wait for the sender and
Subscribegoroutines beforeConsumereturns, and makestopForLoopcarry the error so the main path stays the sole writer ofreturnError. Defers are ordered so the channels close with no writers left.