Skip to content

Commit a9d803e

Browse files
committed
fix: Wait for cleanup completion in blocking path to prevent agent map leak
Root cause: In onMessageSend() blocking requests, cleanupProducer() returned a CompletableFuture but we didn't wait for it. The whenComplete callback (which removes agents from runningAgents map) was racing and sometimes not executing before returning to client. Evidence from CI logs: - 193 agents registered - 172 agents removed - 21 agents leaked (stayed in map with status DONE) - Active threads grew from 28 → 47 - Progressive slowdown on CI (2-4 vCPU constraint) Fix: Add .join() to wait for cleanup completion in blocking path. This ensures the whenComplete callback executes and the agent is removed from the runningAgents map before returning to client. For non-blocking/streaming paths, cleanup continues in background as before.
1 parent 5e9eab6 commit a9d803e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ public EventKind onMessageSend(MessageSendParams params, ServerCallContext conte
220220
if (interruptedOrNonBlocking) {
221221
trackBackgroundTask(cleanupProducer(taskId, queue, false));
222222
} else {
223-
cleanupProducer(taskId, queue, false);
223+
// For blocking requests, wait for cleanup to complete to ensure agent is removed from map
224+
cleanupProducer(taskId, queue, false).join();
224225
}
225226
}
226227

0 commit comments

Comments
 (0)