Skip to content

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

Closed

Description

@MisterVVP

Context

The CI performance matrix has shown an intermittent failure in the wire-level gRPC performance path.

The failure was observed in GitHub Actions run:

  • Run: 37224489704
  • Attempt 1: failed
  • Attempt 2: passed without code changes
  • Failing coordinate: wire / grpc / inmemory / concurrency=16
  • Requests per scenario: 1000

The rerun of the same workflow and commit passed the entire performance matrix, including the previously failing coordinate.

This suggests a nondeterministic concurrency/lifecycle problem rather than a deterministic functional or performance regression.

Observed failure

During attempt 1, the relevant performance results were:

wire grpc inmemory c1   -> 0 errors
wire grpc inmemory c4   -> 0 errors
wire grpc inmemory c16  -> 4327 errors
wire grpc inmemory c64  -> 0 errors

All PostgreSQL, JSON-RPC, and HTTP+JSON coordinates completed without operation errors.

The failing grpc / inmemory / concurrency=16 result contained:

IdleStream_ClientCancellationLatency:
  success=673
  errors=327

PushConfig_Create:
  success=0
  errors=1000

PushConfig_Get:
  success=0
  errors=1000

PushConfig_List:
  success=0
  errors=1000

PushConfig_Delete:
  success=0
  errors=1000

The four push-config scenarios appear to be secondary failures.

The wire driver returns an entire scenario as failed when fixture preparation cannot contact or initialize the SUT:

if (!PrepareFocusedWireFixture(...)) {
  ScenarioResult failed;
  failed.scenario = scenario;
  failed.operations = options.requests;
  failed.errors = options.requests;
  return failed;
}

This matches the 1000/1000 failures reported for each push-config scenario.

Suspicious behavior

The artifact for the failing gRPC/in-memory/concurrency-16 SUT contained an empty SUT log:

performance_sut_inmemory_<port>.log
size: 0 bytes

The surrounding gRPC coordinates produced normal SUT shutdown logs.

This strongly suggests that performance_sut may have exited unexpectedly during the concurrent idle-stream cancellation workload.

However, the current performance runner does not make that conclusion definitive.

SutProcess.__exit__() only performs shutdown handling when the child process is still running. If the process has already exited unexpectedly, its exit status is not surfaced as an explicit test failure with return-code/signal diagnostics.

As a result, CI currently reports the later operation failures rather than the possible original SUT process failure.

Relevant scenario

IdleStream_ClientCancellationLatency exercises the following sequence concurrently:

auto stream = client->SubscribeTask(request, observer, call_options);

if (!stream.ok() || !observer.WaitForEventCount(1)) {
  ...
}

stream.value()->Cancel();

lf::a2a::v1::CancelTaskRequest cancel_request;
cancel_request.set_id(task_id);
const bool server_stream_retired = client->CancelTask(cancel_request, call_options).ok();

For gRPC this involves at least:

  • GrpcTransport::SubscribeTask();
  • StreamHandle::Cancel();
  • gRPC ClientContext cancellation;
  • GrpcServerTransport::SubscribeToTask();
  • StreamCancellationWatcher;
  • ServerStreamSession::Cancel() / stream lifecycle;
  • concurrent unary CancelTask() while the subscription is being cancelled.

The intermittent nature of the failure makes lifetime ordering, cancellation races, or shutdown/cleanup ordering worth investigating.

Reproduction

Start with a focused reproduction instead of running the complete performance matrix:

A2A_PERF_TRANSPORTS=grpc \
A2A_PERF_STORE_BACKENDS=inmemory \
A2A_PERF_REQUESTS=1000 \
A2A_PERF_CONCURRENCY=16 \
A2A_PERF_WARMUP_SECONDS=0 \
A2A_PERF_SCENARIOS=IdleStream_ClientCancellationLatency \
./scripts/run_performance_tests.sh

Run the same coordinate repeatedly.

The issue should not be considered reproduced only by an individual request failure; capture whether performance_sut exits, terminates by signal, hangs, or remains alive.

If useful, also compare:

concurrency=4
concurrency=16
concurrency=64

because only c16 failed in the original CI attempt.

Investigation scope

1. Improve unexpected SUT exit diagnostics

Update the performance runner so an unexpected performance_sut exit is reported immediately and explicitly.

Capture at least:

  • exit code;
  • signal where applicable;
  • transport/store/concurrency coordinate;
  • current scenario;
  • tail of the SUT log.

Do not allow a dead SUT to be silently converted into thousands of downstream operation failures.

2. Stress the gRPC cancellation path

Repeatedly run:

grpc / inmemory / concurrency=16 / IdleStream_ClientCancellationLatency

Try to reproduce under:

  • normal Release build;
  • ASan/UBSan;
  • ThreadSanitizer where practical.

The investigation should focus on SDK-owned synchronization and lifetime handling before attributing failures to gRPC internals.

3. Review client-side cancellation lifetime

Inspect:

  • GrpcTransport::SubscribeTask();
  • StreamHandle::Cancel();
  • ClientContext ownership;
  • stream worker lifetime;
  • observer lifetime;
  • ordering between cancellation, reader->Read(), reader->Finish(), worker join, and handle destruction.

Check whether concurrent cancellation can leave a worker referencing an observer, context, stream reader, or transport object whose lifetime has already ended.

4. Review server-side cancellation lifetime

Inspect:

  • GrpcServerTransport::SubscribeToTask();
  • StreamCancellationWatcher;
  • ServerStreamSession;
  • task subscription publication/cancellation;
  • interaction between client disconnect and the subsequent unary CancelTask().

Pay particular attention to:

  • raw pointers captured by watcher threads;
  • destruction ordering;
  • cancellation occurring while Next() is blocked;
  • multiple concurrent calls to Cancel();
  • stream/session destruction while cancellation watcher work is still in progress.

5. Compare against neighboring concurrency levels

Determine why the original failure occurred at concurrency 16 while:

c1  passed
c4  passed
c64 passed

Do not assume concurrency 16 itself is special. This may simply be scheduling-sensitive.

6. A/B recent HTTP streaming change if needed

If focused gRPC stress cannot reproduce reliably, perform an A/B comparison:

  1. current PR state;
  2. revert only the recent src/http/http_client_streaming.cpp notification-order change;
  3. run the exact same focused gRPC stress loop.

This is intended to distinguish direct causation from incidental scheduling changes.

Non-goals

  • Hiding the problem with retries.
  • Lowering concurrency.
  • Ignoring operation errors because a rerun passed.
  • Changing performance thresholds.
  • Disabling the failing scenario.
  • Adding sleeps to make the race less likely.
  • Treating third-party gRPC code as the root cause without first excluding SDK-owned lifetime/synchronization bugs.

Acceptance criteria

  • The exact failing coordinate can be stress-tested independently of the full matrix.
  • The performance runner reports unexpected performance_sut termination with exit-code/signal information.
  • A dead SUT cannot silently turn into multiple misleading downstream scenario failures.
  • The gRPC stream cancellation/client/server lifetime paths are reviewed for races and use-after-free risks.
  • Any identified SDK race/lifetime bug has a focused regression test.
  • The focused gRPC cancellation workload passes repeatedly under the normal build.
  • Relevant sanitizer coverage passes.
  • The normal performance smoke reports zero operation errors.
  • ./scripts/verify_changes.sh passes.
  • ./scripts/run_clang_tidy.sh build passes.
  • Repository-wide clang-format --dry-run --Werror passes.

Useful starting points

  • tests/performance/a2a_wire_performance_driver.cpp
  • scripts/performance_runner.py
  • src/client/transport/grpc_transport.cpp
  • src/client/client.cpp
  • src/server/transport/grpc_server_transport.cpp
  • src/server/transport/stream_cancellation_watcher.cpp
  • src/server/transport/stream_cancellation_watcher.h
  • include/a2a/server/server_stream_session.h
  • src/server/task_subscription_service.cpp
  • relevant gRPC transport cancellation unit/integration tests

Original CI evidence

The original failing run reported:

[perf] done wire transport=grpc store=inmemory concurrency=16 rows=15 errors=4327

followed by:

scenario=IdleStream_ClientCancellationLatency
success=673 errors=327

scenario=PushConfig_Create
success=0 errors=1000

scenario=PushConfig_Delete
success=0 errors=1000

scenario=PushConfig_Get
success=0 errors=1000

scenario=PushConfig_List
success=0 errors=1000

The rerun of the same commit completed:

wire transport=grpc store=inmemory concurrency=16
rows=15
errors=0

This issue should therefore be treated as an intermittent concurrency/lifecycle failure until the exact termination mechanism is identified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions