Skip to content

fix(grpc): preserve graceful streaming shutdown#443

Merged
yordis merged 1 commit into
masterfrom
yordis/fix-grpc-streaming-shutdown
Jul 19, 2026
Merged

fix(grpc): preserve graceful streaming shutdown#443
yordis merged 1 commit into
masterfrom
yordis/fix-grpc-streaming-shutdown

Conversation

@yordis

@yordis yordis commented Jul 19, 2026

Copy link
Copy Markdown
Member
  • Long-lived gRPC streams must not force graceful shutdown to wait for the server timeout.
  • Shutdown-driven disconnects must remain retryable without changing ordinary client cancellation.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented Jul 19, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes gRPC shutdown and subscription cancellation on a core read path; behavior is well covered by new tests but affects all long-lived stream clients during node stop.

Overview
Graceful shutdown for gRPC streaming so the host does not wait on open read/subscription streams until a timeout. Streaming RPCs (not unary) get RequestAborted linked to ApplicationStopping via new GrpcStreamLifetimeMiddleware, wired in ClusterVNodeStartup after routing.

When shutdown drives that cancellation, GrpcServerShutdownInterceptor maps it to Unavailable with trailer server-shutting-down (RpcExceptions.ServerShuttingDown), so clients can treat it as retryable. Client-initiated aborts still surface as normal OperationCanceledException.

Subscription enumerators (AllSubscription, filtered, stream) rethrow cancel with the caller's CancellationToken instead of the internal linked source. Streams.Read drops the cancel→dispose registration and relies on await using plus enumerator cancellation. Unit tests cover middleware, interceptor, and enumerator token behavior.

Reviewed by Cursor Bugbot for commit 94ba180. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ecea38d5-fc5e-48db-ba13-3b7dfb77a4f7

📥 Commits

Reviewing files that changed from the base of the PR and between c002bc9 and 94ba180.

📒 Files selected for processing (14)
  • src/EventStore.Core.Tests/Services/Transport/Enumerators/Enumerator.AllSubscription.Tests.cs
  • src/EventStore.Core.Tests/Services/Transport/Enumerators/Enumerator.AllSubscriptionFiltered.Tests.cs
  • src/EventStore.Core.Tests/Services/Transport/Enumerators/Enumerator.StreamSubscription.Tests.cs
  • src/EventStore.Core.Tests/Services/Transport/Grpc/GrpcServerShutdownInterceptorTests.cs
  • src/EventStore.Core.Tests/Services/Transport/Grpc/GrpcStreamLifetimeMiddlewareTests.cs
  • src/EventStore.Core/ClusterVNodeStartup.cs
  • src/EventStore.Core/Services/Transport/Enumerators/Enumerator.AllSubscription.cs
  • src/EventStore.Core/Services/Transport/Enumerators/Enumerator.AllSubscriptionFiltered.cs
  • src/EventStore.Core/Services/Transport/Enumerators/Enumerator.StreamSubscription.cs
  • src/EventStore.Core/Services/Transport/Grpc/Constants.cs
  • src/EventStore.Core/Services/Transport/Grpc/GrpcServerShutdownInterceptor.cs
  • src/EventStore.Core/Services/Transport/Grpc/GrpcStreamLifetimeMiddleware.cs
  • src/EventStore.Core/Services/Transport/Grpc/RpcExceptions.cs
  • src/EventStore.Core/Services/Transport/Grpc/Streams.Read.cs

Walkthrough

Streaming enumerators now preserve caller cancellation tokens. gRPC streaming requests link host shutdown to request cancellation, translate shutdown cancellations into an Unavailable RPC error, and remove asynchronous disposal callbacks from the read path.

Changes

Streaming cancellation and shutdown

Layer / File(s) Summary
Enumerator cancellation propagation
src/EventStore.Core/Services/Transport/Enumerators/*, src/EventStore.Core.Tests/Services/Transport/Enumerators/*
Subscription enumerators retain caller tokens, rethrow matching cancellations with those tokens, and add tests for all subscription variants.
gRPC streaming shutdown flow
src/EventStore.Core/Services/Transport/Grpc/*, src/EventStore.Core/ClusterVNodeStartup.cs, src/EventStore.Core.Tests/Services/Transport/Grpc/*
Streaming requests link host shutdown into request cancellation, interceptor handling maps shutdown cancellation to an Unavailable RPC error, startup registers the components, and stream disposal uses await using.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HostApplicationLifetime
  participant GrpcStreamLifetimeMiddleware
  participant StreamsRead
  participant GrpcServerShutdownInterceptor
  HostApplicationLifetime->>GrpcStreamLifetimeMiddleware: Cancel ApplicationStopping
  GrpcStreamLifetimeMiddleware->>StreamsRead: Provide linked RequestAborted token
  StreamsRead->>GrpcServerShutdownInterceptor: Propagate streaming cancellation
  GrpcServerShutdownInterceptor-->>StreamsRead: Return server-shutdown RPC error
Loading

Possibly related PRs

Poem

A bunny hops where tokens flow,
Through streams that catch the shutdown snow.
The host says stop, the pipes comply,
An Unavailable floats by.
“Caller’s token!” the rabbit sings—
Cancellation keeps its strings.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: preserving graceful shutdown behavior for gRPC streaming calls.
Description check ✅ Passed The description is directly about gRPC stream shutdown behavior and cancellation semantics changed in the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yordis/fix-grpc-streaming-shutdown

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yordis
yordis merged commit 9c48754 into master Jul 19, 2026
22 checks passed
@yordis
yordis deleted the yordis/fix-grpc-streaming-shutdown branch July 19, 2026 03:06
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