Skip to content

Commit

Permalink
client state disconnected일 때 send 금지
Browse files Browse the repository at this point in the history
  • Loading branch information
onee-only committed Dec 30, 2024
1 parent caf8493 commit b5bd526
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conn/internal/conn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from fastapi.websockets import WebSocket
from fastapi.websockets import WebSocket, WebSocketState
from websockets.exceptions import ConnectionClosed
from message import Message
from dataclasses import dataclass
Expand All @@ -23,6 +23,9 @@ async def receive(self):
return Message.from_str(await self.conn.receive_text())

async def send(self, msg: Message):
if self.conn.client_state == WebSocketState.DISCONNECTED:
return

try:
await self.conn.send_text(msg.to_str())
except ConnectionClosed:
Expand Down

0 comments on commit b5bd526

Please sign in to comment.