Skip to content

fix(server): stop interrupted event consumers from busy-spinning - #1346

Merged
kabir merged 4 commits into
a2aproject:mainfrom
rmlopes:fix/1345-consumer-interrupt-spin
Nov 20, 2026
Merged

kabir merged 4 commits into
a2aproject:mainfrom
rmlopes:fix/1345-consumer-interrupt-spin

Conversation

@rmlopes

@rmlopes rmlopes commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

The child-queue close lives in InMemoryQueueManager.close(taskId), not MainQueue.close(), because a graceful MainQueue close keeps its children open by design (#333).

Fixes #1345

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
@rmlopes
rmlopes marked this pull request as ready for review November 17, 2026 16:52

@1AbdullahButt 1AbdullahButt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@kabir
kabir merged commit 36d7998 into a2aproject:main Nov 20, 2026
14 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.

[Bug]: EventConsumer.consumeAll busy-spins after an interrupt and pins virtual-thread carriers

3 participants