Repository navigation
fix: don't shut down streaming servicers when the client closes the stream - #401
Open
grifftatarsky wants to merge 1 commit into
Open
grifftatarsky wants to merge 1 commit into
grifftatarsky wants to merge 1 commit into
Conversation
…tream When the client closes a response stream while the servicer is still yielding, gRPC calls aclose() on the generator and GeneratorExit is thrown at the yield. The except BaseException around each RPC treated that as a UDF error and set the shutdown event. Return instead, as the reducer and reduce streamer do, in the accumulator, mapper, mapstreamer, batchmapper, sinker and source transformer, and in the source's ReadFn and AckFn. Signed-off-by: Griff <grifftatarsky@gmail.com>
grifftatarsky
requested review from
BulkBeing,
kohlisid and
vigith
as code owners
December 4, 2026 00:00
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #401 +/- ##
==========================================
+ Coverage 93.17% 93.20% +0.02%
==========================================
Files 68 68
Lines 3694 3710 +16
Branches 236 236
==========================================
+ Hits 3442 3458 +16
Misses 188 188
Partials 64 64 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #400. Follow-up to #399.
The other async streaming servicers have the same bug as #398. When the client closes a response stream while the servicer is still yielding, gRPC calls
aclose()on the generator andGeneratorExitis thrown at theyield. Each RPC'sexcept BaseExceptionrecords it as a UDF error and sets the shutdown event, so the UDF exits. This adds the sameexcept GeneratorExit: returnas the reducer (#399) and the reduce streamer (#331) to:AccumulateFnMapFnMapFnMapFnSinkFnSourceTransformFnReadFnandAckFnThe mapper and the source transformer weren't on the list in #399, but they have the same handler and fail the same way. The source's
NackFn,PendingFnandPartitionsFnare unary, so they never seeGeneratorExit. The sync servicers aren't changed here.Tests:
test_no_shutdown_when_*stream_closedper RPC in the existing*_shutdown.pyfiles: read the first response, callaclose(), and check that neither the shutdown event nor_erroris set. All 8 fail without the change.tests/test_stream_close.py: the same over a realgrpc.aioserver and client for the mapper, mapstreamer, batchmapper, source transformer andReadFn. The client cancels after one result while the rest are still queued. All 5 fail without the change. The sinker andAckFnsend responses too small to back up, so a client cancel doesn't land on ayieldthere; the unit tests cover them and the accumulator.make testpasses on Python 3.11 and 3.14 (489 passed), black and ruff are clean, andtests/test_stream_close.pypassed 30 runs in a row.One thing I left alone: if the client cancels while the mapper, mapstreamer or source transformer is waiting for input, the
CancelledErrorbranch sets the shutdown event (with no error recorded). That branch is there for SIGTERM, and the servicer can't tell the two apart, so it seemed like a separate question.AI disclosure: the reproduction, the change, the tests and this description were prepared with an AI coding agent (Claude Code).