Class GrpcStreamDeadline
grpc-timeout for a streaming RPC, terminating it
mid-stream with DEADLINE_EXCEEDED when the deadline elapses.
One instance per RPC invocation, created by the handler that begins the stream and threaded through its emission recursion. It is deliberately not stored on a channel attribute: on the HTTP/2 connection-adapter pipeline a single channel is shared by every multiplexed stream, so a channel-scoped guard would be replaced by the next overlapping RPC and the first stream would then consult the wrong one -- the same class of error as the single-slot service/method attribute that this change set already had to fix twice.
The interleaving guarantee. A streaming RPC emits frames asynchronously (per
message delays, write-completion callbacks, breakpoint resumes), so the deadline can fire while a
write is in flight. tryTerminate() is a compare-and-set, so exactly one of "the deadline
fired" and "the stream completed normally" wins, and the loser writes nothing. Emission points
additionally check isTerminated() before writing, so no message can be emitted after the
terminal trailer. Both the timer and the emission callbacks run on the stream's own event loop,
so the CAS resolves an ordering rather than true parallelism -- the CAS is what makes that
ordering explicit instead of assumed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels the deadline timer.Thegrpc-messageto report when this deadline elapses.booleanWhether this stream has already been terminated (by the deadline or by normal completion).schedule(io.netty.channel.ChannelHandlerContext ctx, HttpRequest request, Runnable onDeadline) Schedules deadline termination for a streaming RPC, if the client sent agrpc-timeout.booleanClaims the stream for termination.
-
Constructor Details
-
GrpcStreamDeadline
public GrpcStreamDeadline()
-
-
Method Details
-
schedule
public GrpcStreamDeadline schedule(io.netty.channel.ChannelHandlerContext ctx, HttpRequest request, Runnable onDeadline) Schedules deadline termination for a streaming RPC, if the client sent agrpc-timeout.- Parameters:
ctx- the stream's channel contextrequest- the inbound request, read forgrpc-timeoutonDeadline- invoked on the event loop when the deadline elapses and this guard wins the CAS; it should write the DEADLINE_EXCEEDED trailer and stop the stream- Returns:
- this guard, for chaining
-
tryTerminate
public boolean tryTerminate()Claims the stream for termination. Returnstrueonly for the first caller, so a trailer is never written twice. -
isTerminated
public boolean isTerminated()Whether this stream has already been terminated (by the deadline or by normal completion). Emission points check this so no message follows the terminal trailer. -
cancel
public void cancel()Cancels the deadline timer. Called on normal completion and when the channel goes inactive, so a timer cannot outlive its stream. -
deadlineExceededMessage
Thegrpc-messageto report when this deadline elapses.
-