Repository navigation
Fix cancellation handling in ErrSizedGroup and SizedGroup - #18
Merged
Merged
Conversation
Cancellation was checked only on entry to Go, so callbacks already waiting for a semaphore permit still ran after the group's context was canceled and Wait returned nil. The check now also runs after the permit is acquired, in both locking modes and with or without TermOnErr. The context error is recorded once, running callbacks finish and keep their own errors. TestErrorSizedGroup_CancelWithActiveErrors used to rely on queued callbacks running after cancel. It now waits for all callbacks to start before canceling.
Coverage Report for CI Build 37140236136Coverage increased (+0.06%) to 98.93%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation correctly handles queued cancellation across supported modes with focused regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Ensures queued ErrSizedGroup callbacks are skipped after context cancellation while preserving errors from active callbacks.
Changes:
- Rechecks cancellation after semaphore acquisition.
- Adds coverage across locking and termination modes.
- Clarifies cancellation behavior in API documentation.
| File | Description |
|---|---|
README.md |
Documents cancellation semantics. |
group_options.go |
Clarifies the Context option. |
errsizedgroup.go |
Skips queued callbacks after cancellation. |
errsizedgroup_test.go |
Adds regression coverage and updates active-error setup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ive call With Preemptive the permit is taken in Go before the goroutine starts. When the goroutine then found the context canceled it returned without unlocking, so each such call took one permit away from the group for good. The unlock is now deferred and covers the skip path as well as the normal one.
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.
callbacks waiting for a semaphore permit in
ErrSizedGroupstill ran after the group's context was canceled, andWaitreturned nil. Cancellation was checked only on entry toGo.the check now also runs after the permit is acquired, in default and
Preemptivemodes, with or withoutTermOnErr. The context error is recorded once. Running callbacks are not interrupted and keep their own errors.TestErrorSizedGroup_CancelWithActiveErrorsrelied on queued callbacks running after cancel, so it now waits for all callbacks to start before canceling.second commit:
SizedGroupwithPreemptiveleaked a permit on cancel. The permit is taken inGobefore the goroutine starts, and the goroutine returned on a canceled context without unlocking, so each such call removed one permit from the group. The unlock is now deferred and covers the skip path too. The default-mode ordering inSizedGroupis unchanged.Related to #17, which fixed the same ordering for
TermOnErr.