call websocket close in channel close

This commit is contained in:
Timothy Pogue 2022-09-10 15:12:18 -06:00
parent 2afd5c202c
commit 0bc18ea33c
2 changed files with 5 additions and 3 deletions

View File

@ -71,6 +71,7 @@ class WebSocketChannel:
Close the WebSocketChannel Close the WebSocketChannel
""" """
await self._websocket.close()
self._closed = True self._closed = True
def is_closed(self) -> bool: def is_closed(self) -> bool:

View File

@ -56,7 +56,9 @@ class WebSocketProxy:
Close the websocket connection, only supported by FastAPI WebSockets Close the websocket connection, only supported by FastAPI WebSockets
""" """
if hasattr(self._websocket, "close"): if hasattr(self._websocket, "close"):
try:
return await self._websocket.close(code) return await self._websocket.close(code)
except RuntimeError:
pass pass
async def accept(self): async def accept(self):
@ -65,4 +67,3 @@ class WebSocketProxy:
""" """
if hasattr(self._websocket, "accept"): if hasattr(self._websocket, "accept"):
return await self._websocket.accept() return await self._websocket.accept()
pass