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

Gracefully handle websocket errors on python side #2157

Merged
merged 2 commits into from
Apr 4, 2023

Conversation

timkpaine
Copy link
Member

@timkpaine timkpaine commented Mar 28, 2023

Disconnect-related errors were handled for aiohttp and starlette when waiting for the client to send a message, this PR adds that same support to tornado but also handles disconnect when trying to send outbound messages.

Note While testing, I noticed the route to the themes is incorrect, this is particularly noticeable after the recent theme changes

@timkpaine timkpaine added the bug Concrete, reproducible bugs label Mar 28, 2023
@timkpaine timkpaine force-pushed the tkp/fastapidisconnect branch from 5cfe709 to 292a965 Compare March 28, 2023 19:58
@timkpaine timkpaine marked this pull request as ready for review March 28, 2023 22:50
Copy link
Member

@texodus texodus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Looks good!

await self._ws.send_bytes(message)
else:
await self._ws.send_str(message)
except WebSocketError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about the ecosystem of possible exceptions here, but I have spent countless hours of my life chasing bugs that would've been immediately obvious had they not been swallowed by a blanket catch block. At minimum, some comments about what to expect in these cases and why would be super helpful - but I propose we generally try to handle specific exceptions instead, which would also communicate intent here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also in this case merits a debug log, now that I think about it.

@texodus texodus merged commit 4779250 into master Apr 4, 2023
@texodus texodus deleted the tkp/fastapidisconnect branch April 4, 2023 14:44
@texodus texodus changed the title gracefully handle websocket errors on python side, fixes #2132 Gracefully handle websocket errors on python side Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Concrete, reproducible bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants