Skip to content

Commit

Permalink
conn.send시 ConnectionClosed 예외처리
Browse files Browse the repository at this point in the history
  • Loading branch information
onee-only committed Dec 20, 2024
1 parent 7171853 commit 6e7f8a6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion conn/internal/conn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from fastapi.websockets import WebSocket
from websockets.exceptions import ConnectionClosed
from message import Message
from dataclasses import dataclass

Expand All @@ -22,4 +23,8 @@ async def receive(self):
return Message.from_str(await self.conn.receive_text())

async def send(self, msg: Message):
await self.conn.send_text(msg.to_str())
try:
await self.conn.send_text(msg.to_str())
except ConnectionClosed:
# 커넥션이 종료되었는데도 타이밍 문제로 인해 커넥션을 가져왔을 수 있음.
return

0 comments on commit 6e7f8a6

Please sign in to comment.