Repository navigation
fix(server): stop interrupted event consumers from busy-spinning - #1346
Conversation
An interrupted EventConsumer now fails its stream with InternalError and closes its queue, instead of polling again with the interrupt flag set. InMemoryQueueManager.close(taskId) now also closes the task's child queues, as the QueueManager.close contract states, so closing a task queue ends its consumers. consumeOne now wraps the spec InternalError, not java.lang.InternalError. This fixes a2aproject#1345
1AbdullahButt
left a comment
There was a problem hiding this comment.
The interrupt check looks right. dequeueEventItem re-sets the flag and returns null, so testing isInterrupted() on the null path is the only place the loop can tell an interrupt from a timeout. Failing the stream with InternalError and catching a RuntimeException from the close (for the interrupted JDBC case) both make sense.
On the InMemoryQueueManager.close change: it matches what the QueueManager.close javadoc already promises ("closes the MainQueue and all ChildQueues"). Before this, a graceful MainQueue.close() only called children.clear(), so consumers polling a child never ended, which is the workaround the issue suggests. It's a separate fix from the busy loop, so it may be worth a line in the PR description.
One small thing from that change: for a finalized task, closeChildren() makes the last childClosing call this.doClose(...), and then existing.close() calls doClose again. MainQueue.doClose runs the onCloseCallbacks before super.doClose checks closed, so the callbacks now run twice on that path. Today the only callback is the cleanup one, and a second queues.remove does nothing, so there's no visible effect. An if (isClosed()) return; at the top of MainQueue.doClose would keep it that way if someone adds a callback that isn't idempotent.
Reviewed with help from Claude Code.
The child-queue close lives in
InMemoryQueueManager.close(taskId), notMainQueue.close(), because a graceful MainQueue close keeps its children open by design (#333).Fixes #1345