Compare commits

...
Sign in to create a new pull request.

3 commits

Author SHA1 Message Date
J. Nick Koston
75cf02cad8
Merge branch 'dev' into ingress_dropping_close 2024-11-08 23:24:44 +00:00
J. Nick Koston
b2a737cf56
Merge branch 'dev' into ingress_dropping_close 2024-11-03 00:50:32 -05:00
J. Nick Koston
98601da3ea
Fix ingress websocket forward not closing the websocket
Becuase the async iterator was used, it would stop iteration as soon
as a close message was seen. This meant we would never send close to
the other side
2024-09-25 07:56:47 -05:00

View file

@ -284,23 +284,32 @@ def _is_websocket(request: web.Request) -> bool:
)
_CLOSE_TYPES = {
aiohttp.WSMsgType.CLOSE,
aiohttp.WSMsgType.CLOSING,
aiohttp.WSMsgType.CLOSED,
}
async def _websocket_forward(
ws_from: web.WebSocketResponse | ClientWebSocketResponse,
ws_to: web.WebSocketResponse | ClientWebSocketResponse,
) -> None:
"""Handle websocket message directly."""
try:
async for msg in ws_from:
if msg.type is aiohttp.WSMsgType.TEXT:
while msg := await ws_from.receive():
msg_type = msg.type
if msg_type is aiohttp.WSMsgType.TEXT:
await ws_to.send_str(msg.data)
elif msg.type is aiohttp.WSMsgType.BINARY:
elif msg_type is aiohttp.WSMsgType.BINARY:
await ws_to.send_bytes(msg.data)
elif msg.type is aiohttp.WSMsgType.PING:
elif msg_type is aiohttp.WSMsgType.PING:
await ws_to.ping()
elif msg.type is aiohttp.WSMsgType.PONG:
elif msg_type is aiohttp.WSMsgType.PONG:
await ws_to.pong()
elif ws_to.closed:
elif msg_type in _CLOSE_TYPES:
await ws_to.close(code=ws_to.close_code, message=msg.extra) # type: ignore[arg-type]
break
except RuntimeError:
_LOGGER.debug("Ingress Websocket runtime error")
except ConnectionResetError: