Fix _flushQueue stuck on callback error#890
Conversation
…k errors A throwing callback in _flushQueue() caused two issues: 1. The failing row was never dequeued, creating an infinite retry loop that blocked all subsequent queued tasks 2. _flushingQueue was never reset to false, permanently locking the queue for the DO instance lifetime Fix: wrap each callback in try-catch-finally to always dequeue items and reset the flushing flag. Missing callbacks are also dequeued instead of being skipped indefinitely. Closes #883
🦋 Changeset detectedLatest commit: b229430 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
/bonk would deploying this fix existing stuck DOs/queues? |
commit: |
|
Here's the critical finding. Let me answer the question: Short answer: Partially. It depends on which bug bit you. This fix addresses two bugs, and they have different recovery stories: Bug 1:
|
|
/bonk can you add this recommendation to the changeset so people will know when they see the changelog? |
Co-authored-by: threepointone <threepointone@users.noreply.github.com>
|
Updated the changeset to include the recovery recommendation. The added note explains:
|
* fix(agents): prevent _flushQueue from permanently blocking on callback errors A throwing callback in _flushQueue() caused two issues: 1. The failing row was never dequeued, creating an infinite retry loop that blocked all subsequent queued tasks 2. _flushingQueue was never reset to false, permanently locking the queue for the DO instance lifetime Fix: wrap each callback in try-catch-finally to always dequeue items and reset the flushing flag. Missing callbacks are also dequeued instead of being skipped indefinitely. Closes #883 * Added recovery note to changeset Co-authored-by: threepointone <threepointone@users.noreply.github.com> --------- Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: threepointone <threepointone@users.noreply.github.com>
Here's a summary of the changes made to fix issue #883:
Changes
Root cause
_flushQueue()inpackages/agents/src/index.ts:1555had two bugs:callback.bind(this)(...)threw,this.dequeue(row.id)was skipped, the error broke out of thewhile(true)loop, and the row permanently stayed incf_agents_queues, creating an infinite retry loop that blocked all subsequent items._flushingQueuenever reset on error -- the error propagating out of the while loop meantthis._flushingQueue = falseon the last line never executed, permanently locking the queue for the DO instance's lifetime.Fix (
packages/agents/src/index.ts)while(true)loop in atry/finallyto guarantee_flushingQueueis always reset tofalsetry/catch/finallyso that:this.dequeue(row.id)always runs in thefinallyblock, removing the item regardless of success or failuredequeue()instead of justcontinue, preventing orphaned rowsTests
packages/agents/src/tests/agents/queue.ts-- test agent with success and throwing callbackspackages/agents/src/tests/queue.test.ts-- 3 tests covering:Verification
Closes #883
github run