Repository navigation
v0.7.1 fix(jobworker): skip error reporting for jobs cancelled during shutdown - #9
Merged
Merged
Conversation
A dispatch cancelled during shutdown is an expected interruption: the job is reset and retried without consuming a retry attempt, so reporting it via OnError or logging it at ERROR/WARN is misleading noise. DoJob and the worker dispatch loop now skip OnError and the error/warning log when the error is (or wraps) context.Canceled. Genuine failures and per-job JobTimeout (context.DeadlineExceeded) are unaffected. Adds a DB-free test covering the guard. Releases v0.7.1.
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.
Summary
A job dispatch cancelled during shutdown was still logged as
ERRORand sent tothe
OnErrorcallback, even though the job is simply reset and retried (no retryattempt consumed). This is expected shutdown noise, not a failure. This PR guards
both reporting points so a
context.Canceledinterruption is handled quietly.What changed
jobworker/dojob.go— inDoJob, theOnErrorcall and the "Job error"ERROR/WARNlog are now skipped when the worker's error is (or wraps)context.Canceled. The error is still returned andjob.ErrorMsg/ErrorDataare still set, so
doJobAndSaveResultInDBstill detects the cancellation andresets/retries the job exactly as before.
jobworker/workerthreads.go— the worker dispatch loop skipsOnErrorandthe "Error while dispatching the job"
ERRORlog whendoJobAndSaveResultInDBreturns acontext.Canceled(the shutdown reset pathreturns
ctx.Err()).jobworker/dojob_internal_test.go— new DB-free test:OnErroris skippedfor a direct and a wrapped
context.Canceled, still fires for a genuinefailure, and the cancellation still propagates out of
DoJob.The
OnErrorcontract ("called for every error that would also be logged") ispreserved: the log and the callback are skipped together.
Why it's correct
errors.Is(err, context.Canceled)traverses botherrs.WrapWithFuncParams(via
withCallStack.Unwrap) anderrors.Join, so the guard fires on thewrapped return values (verified by the new test).
JobTimeout(context.DeadlineExceeded) is deliberately notsuppressed — those jobs genuinely ran too long and still consume a retry.
Known consideration (not a blocker)
The guard suppresses any error whose chain contains
context.Canceled, includingthe rare case where a worker returns a cancel-wrapped error while the worker
thread's context is still alive (not a real shutdown). Such a job is reset and
retried without consuming an attempt — pre-existing behavior — but now with no
log/
OnErrorsignal. This matches the intended "a cancelled dispatch is always anexpected shutdown interruption" framing. If we later want to scope it strictly to
shutdown, gate the
workerthreads.goguard onctx.Err() != nilinstead.Testing
./scripts/run-tests.sh—go vet/revive/gosecclean, all packages pass(
jobqueue,jobworker,jobworkerdb,tests), including the new guard test.Release
Bumps
VERSIONtov0.7.1and adds the CHANGELOG entry.