Skip to content

Commit 1f6d98e

Browse files
fix: do not ignore all RuntimeErrors, only for websocket closed.
A runtime error also occurs when a send is triggered from the same event loop thread.
1 parent e1ae701 commit 1f6d98e

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

solara/server/starlette.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,21 @@ async def _send_bytes_exc(self, data: bytes):
133133
await self.ws.send_bytes(data)
134134
except (websockets.exceptions.ConnectionClosed, starlette.websockets.WebSocketDisconnect, RuntimeError) as e:
135135
# starlette throws a RuntimeError once you call send after the connection is closed
136-
raise websocket.WebSocketDisconnect() from e
136+
if isinstance(e, RuntimeError) and "close message" in repr(e):
137+
raise websocket.WebSocketDisconnect() from e
138+
else:
139+
raise
137140

138141
async def _send_text_exc(self, data: str):
139142
# make sures we catch the starlette/websockets specific exception
140143
# and re-raise it as a websocket.WebSocketDisconnect
141144
try:
142145
await self.ws.send_text(data)
143146
except (websockets.exceptions.ConnectionClosed, starlette.websockets.WebSocketDisconnect, RuntimeError) as e:
144-
# starlette throws a RuntimeError once you call send after the connection is closed
145-
raise websocket.WebSocketDisconnect() from e
147+
if isinstance(e, RuntimeError) and "close message" in repr(e):
148+
raise websocket.WebSocketDisconnect() from e
149+
else:
150+
raise
146151

147152
def close(self):
148153
if self.portal is None:

0 commit comments

Comments
 (0)