Skip to content

Commit ed0f60e

Browse files
kabirclaude
andcommitted
fix: clear awaitingFinalEvent flag on queue when timeout reached
The timeout logic was setting a local variable to false, but the next iteration would read true again from queue.isAwaitingFinalEvent(), causing the grace period to never start. Added clearAwaitingFinalEvent() method to ChildQueue to properly clear the flag on the queue itself. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 90678ba commit ed0f60e

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

server-common/src/main/java/io/a2a/server/events/EventConsumer.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ public Flow.Publisher<EventQueueItem> consumeAll() {
114114
if (pollTimeoutsWhileAwaitingFinal >= MAX_POLL_TIMEOUTS_AWAITING_FINAL) {
115115
LOGGER.debug("Waited {} timeouts for final event but it hasn't arrived - proceeding with normal timeout logic (queue={})",
116116
pollTimeoutsWhileAwaitingFinal, System.identityHashCode(queue));
117-
awaitingFinal = false; // Give up waiting, let normal timeout logic proceed
117+
// Clear the flag on the queue itself, not just the local variable
118+
if (queue instanceof EventQueue.ChildQueue) {
119+
((EventQueue.ChildQueue) queue).clearAwaitingFinalEvent();
120+
}
121+
awaitingFinal = false; // Also update local variable for this iteration
118122
}
119123
} else {
120124
pollTimeoutsWhileAwaitingFinal = 0; // Reset when event arrives or queue not awaiting

server-common/src/main/java/io/a2a/server/events/EventQueue.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,15 @@ void expectFinalEvent() {
820820
LOGGER.debug("ChildQueue {} now awaiting final event", System.identityHashCode(this));
821821
}
822822

823+
/**
824+
* Called by EventConsumer when it has waited too long for the final event.
825+
* This allows normal timeout logic to proceed if the final event never arrives.
826+
*/
827+
void clearAwaitingFinalEvent() {
828+
awaitingFinalEvent = false;
829+
LOGGER.debug("ChildQueue {} cleared awaitingFinalEvent flag (timeout)", System.identityHashCode(this));
830+
}
831+
823832
@Override
824833
public void close() {
825834
close(false);

0 commit comments

Comments
 (0)