Skip to content

narrow bare except around _try_inline_read to Exception in five readers#3639

Open
HrachShah wants to merge 1 commit into
tornadoweb:masterfrom
HrachShah:fix/iostream-inline-read-bare-except-narrow
Open

narrow bare except around _try_inline_read to Exception in five readers#3639
HrachShah wants to merge 1 commit into
tornadoweb:masterfrom
HrachShah:fix/iostream-inline-read-bare-except-narrow

Conversation

@HrachShah

Copy link
Copy Markdown

The bare 'except:' in read_until_regex, read_until, read_bytes, read_into, and read_until_close was wrapping self._try_inline_read() so the caller could install a done_callback that pulls .exception() off the future and silence the 'Future exception was never retrieved' warning before re-raising.

That bare except also caught BaseException, so a KeyboardInterrupt, SystemExit, asyncio.CancelledError, MemoryError, or RecursionError raised inside _try_inline_read() (or any of the per-call setup just above the try block, like re.compile()) was intercepted, queued the done_callback, then re-raised — meaning Ctrl-C during a network read briefly invoked a useless future.add_done_callback on its way out instead of cancelling the awaitable immediately.

Narrowing to 'except Exception:' preserves the documented intent (silence the unexamined-future warning for ordinary failures like UnsatisfiableReadError, StreamClosedError, OSError, ValueError from re.compile, and LookupError from a bad regex) while letting real shutdown signals propagate straight through to the awaiting coroutine.

All 142 iostream tests pass (61 skipped, no new failures).

The bare 'except:' in read_until_regex, read_until, read_bytes, read_into,
and read_until_close was wrapping self._try_inline_read() so the caller
could install a done_callback that pulls .exception() off the future and
silence the 'Future exception was never retrieved' warning before
re-raising. That bare except also caught BaseException, so a
KeyboardInterrupt, SystemExit, asyncio.CancelledError, MemoryError, or
RecursionError raised inside _try_inline_read() (or any of the per-call
setup just above the try block, like re.compile()) was intercepted,
queued the done_callback, then re-raised — meaning Ctrl-C during a
network read briefly invoked a useless future.add_done_callback on its
way out instead of cancelling the awaitable immediately.

Narrowing to 'except Exception:' preserves the documented intent
(silence the unexamined-future warning for ordinary failures like
UnsatisfiableReadError, StreamClosedError, OSError, ValueError from
re.compile, and LookupError from a bad regex) while letting real
shutdown signals propagate straight through to the awaiting coroutine.
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