Skip to content

channel-range loops to be cancellable while idle#20942

Merged
AskAlexSharov merged 3 commits into
mainfrom
alex/cancelable_worker_35
May 13, 2026
Merged

channel-range loops to be cancellable while idle#20942
AskAlexSharov merged 3 commits into
mainfrom
alex/cancelable_worker_35

Conversation

@AskAlexSharov

Copy link
Copy Markdown
Collaborator

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 select over both ctx.Done() and the work channel. Channels that are closed by the producer also get an ok check so the loop exits cleanly.

Affected locations:

  • cmd/utils/app/support_cmd.go: processRequests, processResponses
  • db/integrity/commitment_integrity.go: worker loop over workCh
  • db/seg/parallel_compress.go: extractPatternsInSuperstrings

@AskAlexSharov AskAlexSharov changed the title cmd/utils, db/integrity, db/seg: fix channel-range loops to be cancellable while idle [wip] cmd/utils, db/integrity, db/seg: fix channel-range loops to be cancellable while idle May 1, 2026
AskAlexSharov and others added 2 commits May 8, 2026 10:58
…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>
@AskAlexSharov AskAlexSharov force-pushed the alex/cancelable_worker_35 branch from 71f0940 to 89930de Compare May 8, 2026 04:03
@AskAlexSharov AskAlexSharov changed the title [wip] cmd/utils, db/integrity, db/seg: fix channel-range loops to be cancellable while idle channel-range loops to be cancellable while idle May 8, 2026
@AskAlexSharov AskAlexSharov enabled auto-merge May 8, 2026 06:29
…r_35

# Conflicts:
#	cmd/utils/app/support_cmd.go
@AskAlexSharov AskAlexSharov added this pull request to the merge queue May 13, 2026
Merged via the queue into main with commit a29b88d May 13, 2026
57 checks passed
@AskAlexSharov AskAlexSharov deleted the alex/cancelable_worker_35 branch May 13, 2026 05:39
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