narrow bare except in twisted errback to Exception#3643
Open
HrachShah wants to merge 1 commit into
Open
Conversation
The errback handler for Deferred-to-Future conversion wrapped
failure.raiseException() (the standard way to re-raise a twisted
Failure as its underlying exception) plus a defensive
'raise Exception("errback called without error")' (in case the
Failure wrapped no exception at all). The bare 'except:' caught
every BaseException including KeyboardInterrupt and SystemExit.
The handler's intent is to capture the exception info so it can be
stashed on the Future (so the awaiter sees the right error), so
narrowing to 'except Exception' is the right shape: a real
KeyboardInterrupt raised inside the twisted reactor (e.g. the
caller pressed Ctrl-C in a different thread, or twisted itself
propagated Ctrl-C from a signal handler) should now propagate out
to the tornado event loop instead of being silently converted to
a Future exception that the awaiter would observe as a generic
'errback called without error' message. A real SystemExit raised
inside twisted (e.g. via a signal handler that the user wired
themselves, or a twisted plugin that called sys.exit on a
shutdown) similarly propagates to the IOLoop's atexit hooks
instead of being hidden inside a Future result. MemoryError and
RecursionError are not caught by 'except Exception' either, which
is the right behavior — a Future is the wrong place to attempt to
record a process-level resource exhaustion.
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.
narrow bare except in twisted errback to Exception
The errback handler for Deferred-to-Future conversion wrapped
failure.raiseException() (the standard way to re-raise a twisted
Failure as its underlying exception) plus a defensive
'raise Exception("errback called without error")' (in case the
Failure wrapped no exception at all). The bare 'except:' caught
every BaseException including KeyboardInterrupt and SystemExit.
The handler's intent is to capture the exception info so it can be
stashed on the Future (so the awaiter sees the right error), so
narrowing to 'except Exception' is the right shape: a real
KeyboardInterrupt raised inside the twisted reactor (e.g. the
caller pressed Ctrl-C in a different thread, or twisted itself
propagated Ctrl-C from a signal handler) should now propagate out
to the tornado event loop instead of being silently converted to
a Future exception that the awaiter would observe as a generic
'errback called without error' message. A real SystemExit raised
inside twisted (e.g. via a signal handler that the user wired
themselves, or a twisted plugin that called sys.exit on a
shutdown) similarly propagates to the IOLoop's atexit hooks
instead of being hidden inside a Future result. MemoryError and
RecursionError are not caught by 'except Exception' either, which
is the right behavior — a Future is the wrong place to attempt to
record a process-level resource exhaustion.