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.CancelledError should be caught in "try_log" #174

Open
nirvana-msu opened this issue Sep 29, 2021 · 1 comment
Open

asyncio.CancelledError should be caught in "try_log" #174

nirvana-msu opened this issue Sep 29, 2021 · 1 comment

Comments

@nirvana-msu
Copy link

nirvana-msu commented Sep 29, 2021

If aiozmp RPC server is terminated with KeyboardInterrupt (e.g. ctrl+c), there is inexplicable mess of asyncio.CancelledError being logged for every pending remote request - instead of replying back to the caller with a serialized exception, like it is the case for any other exception being raised (and then exiting cleanly). This happens because you only catch Exception, but KeyboardInterrupt does not inherit from it.

KeyboardInterrupt should be caught here, in addition to Exception:

except Exception as exc:

and also here:

except Exception as exc:

You'd need to reply to caller (same as on other exceptions) and then re-raise or somehow exit cleanly.

@nirvana-msu
Copy link
Author

I think you can scratch the above. On a more careful examination, what seems to be missing is catching CancelledError within try_log. As of Python 3.8, CancelledError extends from BaseException and not Exception (discussion) so it is never caught by except Exception. If you catch that and return, there is just one KeyboardInterrupt logged which is what we want.

The only thing I can't figure out is whether it's actually possible to reply to remote callers? It appears that the transport is closed by that point and I get warnings like WARNING: write to closed ZMQ socket., and then exceptions, if I try to send a reply. I guess I'll have to settle for leaving the caller hanging...

@nirvana-msu nirvana-msu changed the title KeyboardInterrupt should be caught in "process_call_result" and "try_log" asyncio.CancelledError should be caught in "try_log" Oct 2, 2021
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