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

Handle exceptions from server callbacks #337

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

LasseBlaauwbroek
Copy link
Contributor

In its current form, when a server callback throws an exception, it is completely swallowed. Only when the asyncio loop is being shut down might one possibly see that error. On top of that, the connection is never closed, causing any clients to hang, and a memory leak in the server.

This is a proposed fix that reports the exception to the asyncio exception handler. It also makes sure that the connection is always closed, even if the callback doesn't close it explicitly.

Note that the design of AsyncIoStream is directly based on the design of Python's asyncio streams: https://docs.python.org/3/library/asyncio-stream.html These streams appear to have exactly the same flaw. I've reported this here: python/cpython#110894. Since I don't really know what I'm doing, it might be worth seeing what kind of solution they might come up with and model our solution after theirs.

In its current form, when a server callback throws an exception, it is
completely swallowed. Only when the asyncio loop is being shut down might one
possibly see that error. On top of that, the connection is never closed, causing
any clients to hang, and a memory leak in the server.

This is a proposed fix that reports the exception to the asyncio exception
handler. It also makes sure that the connection is always closed, even if the
callback doesn't close it explicitly.

Note that the design of AsyncIoStream is directly based on the design of
Python's asyncio streams: https://docs.python.org/3/library/asyncio-stream.html
These streams appear to have exactly the same flaw. I've reported this here:
python/cpython#110894. Since I don't really know what
I'm doing, it might be worth seeing what kind of solution they might come up
with and model our solution after theirs.
@LasseBlaauwbroek
Copy link
Contributor Author

There has been no activity on my upstream issue. This current fix seems to be working fine. I propose to merge this. We can amend/change to follow the solution upstream comes up with if and when it becomes available.

@haata haata merged commit ca8d120 into capnproto:master Oct 23, 2023
12 checks passed
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.

2 participants