Skip to content

trio_websocket/_impl.py: Don't reply to pings on a locally closed connection#198

Open
geronimogoemon wants to merge 1 commit intopython-trio:masterfrom
geronimogoemon:fix_ping_on_local_closing
Open

trio_websocket/_impl.py: Don't reply to pings on a locally closed connection#198
geronimogoemon wants to merge 1 commit intopython-trio:masterfrom
geronimogoemon:fix_ping_on_local_closing

Conversation

@geronimogoemon
Copy link

@geronimogoemon geronimogoemon commented Mar 28, 2025

I encountered this issue in my application and applied the following fix in my local fork. I am making the PR in case there is interest in applying this fix on the main repo.

For clarity, the source of the problem seems to be the fact that when calling aclose() we will send a CloseConnection message here and then allow context switch on await before we disable processing of incoming messages here but after wsproto will change its connection state to LOCAL_CLOSING. During that time gap we can receive Ping message which will result in exception upon handling it.

Fixes #184

Copy link
Member

Choose a reason for hiding this comment

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

thank you-- would you mind trying to add unit test coverage for this?

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.

_handle_ping_event() occasionally sends to closed socket

2 participants

Comments