channel-range loops to be cancellable while idle#20942
Merged
Merged
Conversation
…lable while idle Replace `for x := range ch` + non-blocking select with a single select on both ctx.Done and the work channel, so goroutines unblock on cancellation even when no items are queued. Affected: - cmd/utils/app/support_cmd.go: processRequests, processResponses - db/integrity/commitment_integrity.go: worker loop over workCh - db/seg/parallel_compress.go: extractPatternsInSuperstrings
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
71f0940 to
89930de
Compare
sudeepdino008
approved these changes
May 8, 2026
…r_35 # Conflicts: # cmd/utils/app/support_cmd.go
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.
Four goroutines used the broken pattern of ranging over a channel with a nested non-blocking select for cancellation. The cancellation check only fires after an item arrives, so goroutines block indefinitely when the queue is empty and the context is cancelled.
Fixed by replacing each with a single
selectover bothctx.Done()and the work channel. Channels that are closed by the producer also get anokcheck so the loop exits cleanly.Affected locations:
cmd/utils/app/support_cmd.go:processRequests,processResponsesdb/integrity/commitment_integrity.go: worker loop overworkChdb/seg/parallel_compress.go:extractPatternsInSuperstrings