Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio functions raising KeyboardInterrupt/SystemExit can produce a deadlock #118

Open
oremanj opened this issue Jan 24, 2023 · 0 comments

Comments

@oremanj
Copy link
Member

oremanj commented Jan 24, 2023

asyncio contains a number of special-cases where KeyboardInterrupt and SystemExit are handled differently than other exceptions: they are allowed to propagate out of the event loop, rather than (or in some cases in addition to) being set as the result of a future or passed to the default_exception_handler. Presumably this was done as an ugly-but-practical solution to the endless stream of "asyncio hangs when you press Ctrl-C!" bugs.

trio_asyncio does not deal well with the event loop raising an exception without resolving all its futures. In some other part of the program, there is a call to run_aio_future which is uninterruptibly waiting to see what that future resolves to. If the event loop exits, the future will never be resolved. Boom, deadlock.

This isn't much of a problem with actual keyboard interrupts, because we can (mostly) route those using restrict_keyboard_interrupt_to_checkpoints so they aren't raised within asyncio-flavored code. But it definitely breaks code that uses KeyboardInterrupt as a normal signaling exception. I ran into this when using prompt_toolkit; by default it produces a KeyboardInterrupt exception when it reads Ctrl+C from the terminal (the terminal is in raw mode so this doesn't produce a SIGINT). Under trio_asyncio such a Ctrl+C can produce a deadlock instead.

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

No branches or pull requests

1 participant