Skip to content

fix: abandon queue entry when GetQueueEntryLockAsync throws#509

Merged
niemyjski merged 1 commit into
mainfrom
fix/queue-job-lock-error-handling
May 8, 2026
Merged

fix: abandon queue entry when GetQueueEntryLockAsync throws#509
niemyjski merged 1 commit into
mainfrom
fix/queue-job-lock-error-handling

Conversation

@niemyjski
Copy link
Copy Markdown
Member

Summary

  • Wraps \GetQueueEntryLockAsync\ in a try-catch in \QueueJobBase.ProcessAsync\ so that if the lock acquisition throws (e.g., network failure in a distributed lock provider), the queue entry is properly abandoned rather than left in-flight until visibility timeout expires
  • Updates the \GetQueueEntryLockAsync\ example in docs to use \TryAcquireAsync\ (matching the \Task<ILock?>\ return type) instead of \AcquireAsync\
  • Documents the error handling behavior in jobs guide, queues guide, and the Foundatio agent skill

Test plan

  • Added \GetQueueEntryLockAsync_WhenLockThrows_AbandonsQueueEntry\ test to \JobQueueTestsBase\ and wired it into \InMemoryJobQueueTests\ and \RedisJobQueueTests\
  • All existing \InMemoryJobQueueTests\ pass (5/5)
  • Full workspace build (\Foundatio.All.slnx) succeeds with 0 warnings

Previously, if GetQueueEntryLockAsync threw an exception (e.g., network failure in a distributed lock provider), the exception would propagate without abandoning the queue entry, leaving it in-flight until the visibility timeout expired.

Now the call is wrapped in a try-catch that logs the error, abandons the entry, and returns JobResult.FromException so the entry is retried promptly.

Also updates the GetQueueEntryLockAsync example in docs to use TryAcquireAsync (matching the Task<ILock?> return type) and documents the error handling behavior in the jobs/queues guides and skill file.
Comment thread src/Foundatio/Jobs/QueueJobBase.cs Dismissed
@niemyjski niemyjski self-assigned this May 8, 2026
@niemyjski niemyjski requested a review from ejsmith May 8, 2026 19:40
@niemyjski niemyjski added the bug label May 8, 2026
@niemyjski niemyjski merged commit 00c8a1a into main May 8, 2026
4 checks passed
@niemyjski niemyjski deleted the fix/queue-job-lock-error-handling branch May 8, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant