Skip to content

Commit 0bb4fb9

Browse files
committed
Don't error on LocalProtoclErrors for ws streams
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.
1 parent 7c39c68 commit 0bb4fb9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/hypercorn/protocol/ws_stream.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from wsproto.extensions import Extension, PerMessageDeflate
1919
from wsproto.frame_protocol import CloseReason
2020
from wsproto.handshake import server_extensions_handshake, WEBSOCKET_VERSION
21-
from wsproto.utilities import generate_accept_token, split_comma_header
21+
from wsproto.utilities import generate_accept_token, LocalProtocolError, split_comma_header
2222

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

335335
async def _send_wsproto_event(self, event: WSProtoEvent) -> None:
336-
data = self.connection.send(event)
337-
await self.send(Data(stream_id=self.stream_id, data=data))
336+
try:
337+
data = self.connection.send(event)
338+
except LocalProtocolError:
339+
pass
340+
else:
341+
await self.send(Data(stream_id=self.stream_id, data=data))
338342

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

0 commit comments

Comments
 (0)