Skip to content

fix(grpc): avoid cross-thread subscription cancellation - #273

Merged
MisterVVP merged 2 commits into
dev-investigate-intermittent-grpc-performance-failurefrom
dev-investigate-and-fix-grpc-performance-failure
Oct 7, 2026
Merged

MisterVVP merged 2 commits into
dev-investigate-intermittent-grpc-performance-failurefrom
dev-investigate-and-fix-grpc-performance-failure

Conversation

@MisterVVP

@MisterVVP MisterVVP commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Motivation

  • Intermittent failures in the gRPC/inmemory performance coordinate (IdleStream_ClientCancellationLatency) pointed to a nondeterministic lifecycle/cancellation race where the server SUT could exit unexpectedly under concurrent client cancellations.
  • The root cause was that some ServerStreamSession implementations block in Next() while a separate cancellation watcher thread polls ::grpc::ServerContext::IsCancelled(), producing cross-thread cancellation churn and delayed server retirement under load.
  • Make gRPC handlers observe cancellation on the gRPC handler thread for sessions that can support interruptible timed reads to avoid cross-thread Cancel() races while preserving compatibility for blocking sessions.

Description

  • Add SupportsTimedNext() to ServerStreamSession with a false default and document its purpose to advertise interruptible timed reads.
  • Implement SupportsTimedNext() override returning true for the task-subscription SubscriptionSession so it advertises timed-read capability.
  • Update gRPC streaming handlers in GrpcServerTransport to: prefer NextFor(kStreamCancellationPollInterval) when SupportsTimedNext() is true, and only create a StreamCancellationWatcher fallback when a session does not support timed reads; also skip empty non-terminal results rather than treating them as end-of-stream.
  • Add a unit assertion that subscription sessions report SupportsTimedNext() in tests/unit/task_subscription_service_test.cpp.

Testing

  • Ran formatting and validation: ./scripts/run_clang_format.sh and clang-format --dry-run --Werror on tracked sources (passed).
  • Full build and test suite: executed the repository build and ran ctest (574 tests) with all tests passing (574/574 passed).
  • Performance validation: ran focused reproduction A2A_PERF_TRANSPORTS=grpc A2A_PERF_STORE_BACKENDS=inmemory A2A_PERF_REQUESTS=1000 A2A_PERF_CONCURRENCY=16 A2A_PERF_SCENARIOS=IdleStream_ClientCancellationLatency ./scripts/run_performance_tests.sh three times and observed zero errors each run. Also ran the mandatory performance smoke check and it reported zero errors.
  • Linters: ran ./scripts/run_clang_tidy.sh build and clang-tidy on the changed test file; changed production and test code passed the targeted clang-tidy checks (the full repository lint run was performed but its default profile was large and lengthy; changed files were validated).

@MisterVVP MisterVVP added the codex Automatic label added by codex agent. Should not be used label Oct 6, 2026 — with ChatGPT Codex Connector
@MisterVVP MisterVVP self-assigned this Oct 6, 2026
@MisterVVP MisterVVP added bug Something isn't working AI agent AI agent contribution maintenance and removed codex Automatic label added by codex agent. Should not be used labels Oct 6, 2026
@MisterVVP MisterVVP changed the title Avoid cross-thread gRPC subscription cancellation fix: avoid cross-thread gRPC subscription cancellation Oct 6, 2026
@MisterVVP MisterVVP changed the title fix: avoid cross-thread gRPC subscription cancellation fix(grpc): avoid cross-thread subscription cancellation Oct 6, 2026
@MisterVVP
MisterVVP marked this pull request as ready for review October 7, 2026 06:06
@MisterVVP
MisterVVP merged commit e68589d into dev-investigate-intermittent-grpc-performance-failure Oct 7, 2026
21 of 22 checks passed
@MisterVVP
MisterVVP deleted the dev-investigate-and-fix-grpc-performance-failure branch October 7, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI agent AI agent contribution bug Something isn't working maintenance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Investigate intermittent gRPC SUT failure during concurrent idle-stream cancellation

1 participant