diff --git a/starlette/websockets.py b/starlette/websockets.py index b7acaa3f0..65b4b5f5c 100644 --- a/starlette/websockets.py +++ b/starlette/websockets.py @@ -110,6 +110,8 @@ async def accept( def _raise_on_disconnect(self, message: Message) -> None: if message["type"] == "websocket.disconnect": + self.application_state = WebSocketState.DISCONNECTED + raise WebSocketDisconnect(message["code"], message.get("reason")) async def receive_text(self) -> str: