Skip to content

fix: don't shut down the reducer when the client closes the stream - #399

Merged
vigith merged 1 commit into
numaproj:mainfrom
grifftatarsky:fix/reducer-stream-close
Dec 3, 2026
Merged

vigith merged 1 commit into
numaproj:mainfrom
grifftatarsky:fix/reducer-stream-close

Conversation

@grifftatarsky

Copy link
Copy Markdown
Contributor

Fixes #398

When the client closes the ReduceFn response stream early, gRPC calls aclose() on the generator and GeneratorExit is thrown at the yield. The reducer's except BaseException treated that as a UDF error and set the shutdown event, so the container exited with status 1. This adds the same except GeneratorExit: return the reduce streamer got in #331.

Tests, in tests/reduce/test_async_reduce_shutdown.py:

  • test_no_shutdown_when_stream_closed: aclose() after the first response sets neither the shutdown event nor _error.
  • test_shutdown_on_error_at_yield: a real exception thrown at the same yield still shuts down, so the new except only covers stream close.
  • test_no_shutdown_when_grpc_client_cancels: the same over a real grpc.aio server and client. The client cancels after one response; a client that reads everything is the control.

The first and third fail without the change. make test passes on Python 3.11 and 3.14 (466 passed), black and ruff are clean, and the gRPC test passed 30 runs in a row.

AI disclosure: the reproduction, the change, the tests and this description were prepared with an AI coding agent (Claude Code).

ReduceFn in the async reducer is an async generator. When the client
closes the response stream before reading every response, gRPC calls
aclose() on it and GeneratorExit is thrown at the yield. The blanket
except BaseException caught it, logged a UDF_EXECUTION_ERROR and set
the shutdown event, so the UDF container exited with status 1.

Return on GeneratorExit instead, as the reduce streamer already does
since numaproj#331. A real exception at the same point still shuts down.

Signed-off-by: Griff <grifftatarsky@gmail.com>
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.10%. Comparing base (f4c3537) to head (8b6a586).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #399      +/-   ##
==========================================
+ Coverage   92.99%   93.10%   +0.11%     
==========================================
  Files          68       68              
  Lines        3654     3656       +2     
  Branches      236      236              
==========================================
+ Hits         3398     3404       +6     
+ Misses        190      188       -2     
+ Partials       66       64       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@grifftatarsky
grifftatarsky marked this pull request as ready for review December 3, 2026 19:48

@vigith vigith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have the same problem in accumulator, mapstreamer, batchmapper, sinker and sourcer

@vigith
vigith merged commit acc4a76 into numaproj:main Dec 3, 2026
11 checks passed
@vigith

vigith commented Dec 3, 2026

Copy link
Copy Markdown
Member

I think we have the same problem in accumulator, mapstreamer, batchmapper, sinker and sourcer

we will create in separate PR

@grifftatarsky

Copy link
Copy Markdown
Contributor Author

I think we have the same problem in accumulator, mapstreamer, batchmapper, sinker and sourcer

we will create in separate PR

You want me to prep that? Happy to

@vigith

vigith commented Dec 3, 2026

Copy link
Copy Markdown
Member

You want me to prep that? Happy to

thank you, could you please comment on #400

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.

Async reducer exits with UDF_EXECUTION_ERROR GeneratorExit when the client closes the stream

2 participants