Skip to content

fix(pool): skip queued Go tasks when the pool context is canceled - #150

Merged
alitto merged 1 commit into
alitto:mainfrom
spicysharkco:fix/go-canceled-context
Oct 24, 2026
Merged

alitto merged 1 commit into
alitto:mainfrom
spicysharkco:fix/go-canceled-context

Conversation

@spicysharkco

Copy link
Copy Markdown
Contributor

Go submits the task unwrapped, so unlike the Submit and TrySubmit variants it never checks the pool context. A Go task still queued when the context is canceled runs anyway and counts as successful, not canceled. The README says drained tasks "are not executed".

a2e34e8 (v2.7.0) moved the context check from readTask to wrapTask. Before it, a queued Go task did not run after cancellation. Go never used wrapTask (pool.go#L333-L335), so it lost the check.

Wrap the task with wrapTask and the pool context, as wrapAndSubmit does. The callback is a no-op because Go has no future. The test mirrors TestPoolStopAndWaitShouldNotDeadlockWhenContextCanceledWithQueuedTasks.

Validation (Go 1.27.0):

  • The new test fails on 52d2178 in 3 of 3 runs with -race and passes with the fix in 50 of 50.
  • go test -race ./..., go vet ./... and git diff --check are clean.
  • Go makes one more allocation per call (2 instead of 1); Submit makes 7.

Go submits the raw function, so unlike Submit, SubmitErr, TrySubmit and
TrySubmitErr it never checks the pool context before running the task.
Tasks still queued when the context is canceled ran anyway and were
counted as successful instead of canceled.

Wrap the task the same way the other submit methods do. The test cancels
the context while a queued Go task waits behind a running one.
@codecov

codecov Bot commented Oct 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.81%. Comparing base (52d2178) to head (c2f3115).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #150   +/-   ##
=======================================
  Coverage   95.81%   95.81%           
=======================================
  Files          11       11           
  Lines         622      622           
=======================================
  Hits          596      596           
  Misses         23       23           
  Partials        3        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@alitto alitto left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Thank you!

@alitto
alitto merged commit 899d406 into alitto:main Oct 24, 2026
18 checks passed
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