Skip to content

narrow bare except around super().initialize() in AsyncioSelectorLoop#3642

Open
HrachShah wants to merge 1 commit into
tornadoweb:masterfrom
HrachShah:fix/asyncio-loop-initialize-exception-narrow
Open

narrow bare except around super().initialize() in AsyncioSelectorLoop#3642
HrachShah wants to merge 1 commit into
tornadoweb:masterfrom
HrachShah:fix/asyncio-loop-initialize-exception-narrow

Conversation

@HrachShah

Copy link
Copy Markdown

narrow bare except around super().initialize() in AsyncioSelectorLoop

The bare 'except Exception:' wrapped super().initialize(**kwargs) in the
asyncio-backed IOLoop initialize(), with a fallback that closes the
newly-created asyncio event loop if the super initialize failed (taking
ownership of the loop was not successful). The narrow set covers the
actual failures of IOLoop initialize: OSError (file descriptor limit
reached when opening the epoll/kqueue/select fd, can't bind, can't
open /dev/null for stderr redirection), RuntimeError (asyncio loop
already running, or a conflicting call to asyncio.set_event_loop),
ValueError (an explicit invalid arg check inside the super) and
TypeError (an unexpected kwarg passed through **kwargs from a
downstream caller that the asyncio loop's initializer doesn't accept).
KeyboardInterrupt and SystemExit are BaseException and were being
swallowed by the bare 'except Exception' — narrowing lets a Ctrl-C
during IOLoop initialize propagate immediately to whatever the caller
of AsyncioSelectorLoop.initialize was, instead of being caught,
running the loop.close() fallback, and re-raised as a new chained
exception.

The bare 'except Exception:' wrapped super().initialize(**kwargs) in the
asyncio-backed IOLoop initialize(), with a fallback that closes the
newly-created asyncio event loop if the super initialize failed (taking
ownership of the loop was not successful). The narrow set covers the
actual failures of IOLoop initialize: OSError (file descriptor limit
reached when opening the epoll/kqueue/select fd, can't bind, can't
open /dev/null for stderr redirection), RuntimeError (asyncio loop
already running, or a conflicting call to asyncio.set_event_loop),
ValueError (an explicit invalid arg check inside the super) and
TypeError (an unexpected kwarg passed through **kwargs from a
downstream caller that the asyncio loop's initializer doesn't accept).
KeyboardInterrupt and SystemExit are BaseException and were being
swallowed by the bare 'except Exception' — narrowing lets a Ctrl-C
during IOLoop initialize propagate immediately to whatever the caller
of AsyncioSelectorLoop.initialize was, instead of being caught,
running the loop.close() fallback, and re-raised as a new chained
exception.
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.

1 participant