Skip to content

Commit

Permalink
Don't error on LocalProtoclErrors for ws streams
Browse files Browse the repository at this point in the history
There is a race condition being hit in the autobahn compliance tests
whereby the client closes the stream and the server responds with an
acknowledgement. Whilst the server responds the app sends a message,
which now errors as the WSConnection state is closed.

As the state is managed by the WSStream, rather than the WSConnection
it makes sense to ignore these errors.
  • Loading branch information
pgjones committed Jan 1, 2024
1 parent 7c39c68 commit 0bb4fb9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hypercorn/protocol/ws_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from wsproto.extensions import Extension, PerMessageDeflate
from wsproto.frame_protocol import CloseReason
from wsproto.handshake import server_extensions_handshake, WEBSOCKET_VERSION
from wsproto.utilities import generate_accept_token, split_comma_header
from wsproto.utilities import generate_accept_token, LocalProtocolError, split_comma_header

from .events import Body, Data, EndBody, EndData, Event, Request, Response, StreamClosed
from ..config import Config
Expand Down Expand Up @@ -333,8 +333,12 @@ async def _send_error_response(self, status_code: int) -> None:
)

async def _send_wsproto_event(self, event: WSProtoEvent) -> None:
data = self.connection.send(event)
await self.send(Data(stream_id=self.stream_id, data=data))
try:
data = self.connection.send(event)
except LocalProtocolError:
pass
else:
await self.send(Data(stream_id=self.stream_id, data=data))

async def _accept(self, message: WebsocketAcceptEvent) -> None:
self.state = ASGIWebsocketState.CONNECTED
Expand Down

0 comments on commit 0bb4fb9

Please sign in to comment.