fix: narrow send_cancel BaseException catch to Exception#1198
Open
fix: narrow send_cancel BaseException catch to Exception#1198
Conversation
`ZMQEnvClient.send_cancel` is a best-effort cleanup op - if the socket fails while sending the cancel notification, we don't want that to break shutdown. But `except BaseException: pass` is too wide: it also swallows `asyncio.CancelledError`, `KeyboardInterrupt`, and `SystemExit`, which is especially wrong in a method called `send_cancel` (literally denying the caller's own cancellation). Narrow to `except Exception: pass`. Transport / socket / ZMQ errors are still quietly swallowed as before; cancellation and interrupt signals now propagate like they should. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
ZMQEnvClient.send_cancelcaughtBaseExceptionand silently passed. Intent was best-effort cleanup — transport/socket errors shouldn't break shutdown. ButBaseExceptionalso swallows:asyncio.CancelledError— denying the caller's cancellation. Particularly ironic in a method literally namedsend_cancel.KeyboardInterrupt— eating user Ctrl-C during cleanup.SystemExit— ignoring explicitsys.exit().Narrowed to
except Exception: pass. Transport / socket / ZMQ errors still swallowed as before; cancellation and interrupt signals now propagate correctly.Changes
Verification
Context
Part of a small audit of `BaseException` catches in verifiers following bugbot's review on #1196. See the plan file for the full inventory; companion PR is #1197 (same narrowing applied to `math_verify` calls in `math_rubric.py`).
Note
Low Risk
Low risk: a narrowly-scoped exception-handling tweak in
send_cancelplus targeted tests; behavior only changes for cancellation/interrupt signals while keeping transport errors best-effort.Overview
ZMQEnvClient.send_cancelnow catchesExceptioninstead ofBaseException, so best-effort cancel notifications still ignore socket/transport failures but no longer suppressasyncio.CancelledError,KeyboardInterrupt, orSystemExit.Adds a new
TestSendCancelErrorHandlingsuite verifying transport errors are swallowed and cancellation/interrupt signals propagate.Reviewed by Cursor Bugbot for commit 6598c35. Bugbot is set up for automated code reviews on this repo. Configure here.