diff --git a/uvicorn/protocols/websockets/websockets_sansio_impl.py b/uvicorn/protocols/websockets/websockets_sansio_impl.py index 880982afa..e8fd063a1 100644 --- a/uvicorn/protocols/websockets/websockets_sansio_impl.py +++ b/uvicorn/protocols/websockets/websockets_sansio_impl.py @@ -369,7 +369,8 @@ async def send(self, message: ASGISendEvent) -> None: elif text_data is not None: self.conn.send_text(text_data.encode()) output = self.conn.data_to_send() - self.transport.write(b"".join(output)) + if not self.transport.is_closing(): + self.transport.write(b"".join(output)) elif message_type == "websocket.close": if not self.transport.is_closing():