Skip to content

Prevent concurrent cancellations of data plane call in ExternalProcessorClientInterceptor - #12996

Open
kannanjgithub wants to merge 1 commit into
grpc:masterfrom
kannanjgithub:ext-proc-client-close-race-handling
Open

Prevent concurrent cancellations of data plane call in ExternalProcessorClientInterceptor#12996
kannanjgithub wants to merge 1 commit into
grpc:masterfrom
kannanjgithub:ext-proc-client-close-race-handling

Conversation

@kannanjgithub

Copy link
Copy Markdown
Contributor

If the ext-proc stream terminates with a non-OK status, the interceptor cancels the downstream data plane call (on the executor thread). Concurrently, the application thread may call cancel() on the returned proxy call (e.g. for user cancellation or cleanup).

Since ClientCallImpl does not synchronize its cancelCalled field, concurrent cancellations from these two threads resulted in a TSAN data race (that was discussed in #12975).

This commit introduces an AtomicBoolean downstreamCancelled in DataPlaneClientCall to guard all downstream cancellations, ensuring that only the first cancellation is forwarded to delayedCall/super.cancel(). This deduplicates and serializes cancellation handling from both the application and the interceptor threads, preventing the data race.

…sorClientInterceptor

If the ext-proc stream terminates with a non-OK status, the interceptor cancels the downstream data plane call (on the executor thread). Concurrently, the application thread may call cancel() on the returned proxy call (e.g. for user cancellation or cleanup).

Since ClientCallImpl does not synchronize its cancelCalled field, concurrent cancellations from these two threads resulted in a TSAN data race (that was discussed in grpc#12975).

This commit introduces an AtomicBoolean downstreamCancelled in DataPlaneClientCall to guard all downstream cancellations, ensuring that only the first cancellation is forwarded to delayedCall/super.cancel(). This deduplicates and serializes cancellation handling from both the application and the interceptor threads, preventing the data race.
@kannanjgithub
kannanjgithub requested a review from sauravzg August 19, 2026 10:18
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.

1 participant