Repository navigation
fix(channelutil): stop join and clone workers on context cancel - #848
Open
dwisiswant0 wants to merge 1 commit into
Open
dwisiswant0 wants to merge 1 commit into
dwisiswant0 wants to merge 1 commit into
Conversation
JoinChannels.Wait and CloneChannels.Wait could block forever after the context was cancelled. Only some of the workers' blocking operations selected on ctx.Done(): the join worker sent to its sink with a bare "sink <- w", and the clone worker received from its source with a bare "<-src". In clone, a cancelled drainAndReset also returned only from the helper, so the worker loop called it again and spun on the non-empty backlog. Relay workers blocked on a stopped parent kept the whole tree alive. Add sendCtx, a send that gives up once ctx is done, and use it for every send in both workers. The clone worker now selects on ctx.Done() when receiving from its source and returns when the drain is aborted. On cancel, workers stop, drop undelivered values and close their sinks, as before; this is now documented on Join and Clone. Tests cover cancel with blocked senders and the uncancelled delivery path for 1 to 7, 9 to 11, 25 and 26 sources and sinks, so single-worker, padded and multi-level relay trees are all exercised. Fixes: #838 Signed-off-by: Dwi Siswanto <git@dw1.io>
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.
JoinChannels.Wait and CloneChannels.Wait could block forever after the
context was cancelled. Only some of the workers' blocking operations
selected on ctx.Done(): the join worker sent to its sink with a bare
"sink <- w", and the clone worker received from its source with a bare
"<-src". In clone, a cancelled drainAndReset also returned only from
the helper, so the worker loop called it again and spun on the
non-empty backlog. Relay workers blocked on a stopped parent kept the
whole tree alive.
Add sendCtx, a send that gives up once ctx is done, and use it for
every send in both workers. The clone worker now selects on ctx.Done()
when receiving from its source and returns when the drain is aborted.
On cancel, workers stop, drop undelivered values and close their sinks,
as before; this is now documented on Join and Clone.
Tests cover cancel with blocked senders and the uncancelled delivery
path for 1 to 7, 9 to 11, 25 and 26 sources and sinks, so
single-worker, padded and multi-level relay trees are all exercised.
Fixes: #838