Skip to content

Commit a6d3157

Browse files
authored
Allow end stream to be dropped in the async server handler (#1323)
Motivation: The async server handler throws an error if the end-of-stream received from the client is dropped. The end-of-stream will only be dropped if the request stream has already been finished. This happens in a few cases: either end-of-stream has already been received, or as a side effect of the task running the user handler completing. The latter case is possible of the user handler does not wait for end of stream (if it encounters an error, for example). This happened periodically in some tests as a result of the user handler completing and receiving end-stream racing. Modifications: - Tolerate dropping end stream in the async server handler. Result: Fewer flakey tests.
1 parent 6e6bdeb commit a6d3157

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Sources/GRPC/AsyncAwaitSupport/GRPCAsyncServerHandler.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,9 @@ internal final class AsyncServerHandler<
492492
case .accepted(queueDepth: _):
493493
break
494494
case .dropped:
495-
/// If we are in the `.active` state then we have yet to encounter an error. Therefore
496-
/// if the request stream source has already terminated then it must have been the result of
497-
/// receiving `.end`. Therefore this `.end` must have been sent by the client after it
498-
/// already sent `.end`, which is a protocol violation.
499-
self.handleError(GRPCError.ProtocolViolation("Message duplicate end of stream"))
495+
// The task executing the user handler will finish the request stream source after the
496+
// user handler completes. If that's the case we will drop the end-of-stream here.
497+
break
500498
}
501499
case .completed:
502500
// We received a message but we're already done: this may happen if we terminate the RPC

0 commit comments

Comments
 (0)