Skip to content

Commit 7bd86ad

Browse files
committed
Pass through disconnection on ws.receive()
1 parent 802e090 commit 7bd86ad

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "truss"
3-
version = "0.11.1rc3"
3+
version = "0.11.1rc15"
44
description = "A seamless bridge from model development to model delivery"
55
authors = [
66
{ name = "Pankaj Gupta", email = "[email protected]" },

truss-chains/truss_chains/remote_chainlet/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,18 @@ async def close(self, code: int = 1000, reason: Optional[str] = None) -> None:
588588
await self._websocket.close(code=code, reason=reason)
589589

590590
async def receive(self) -> Union[str, bytes]:
591+
try:
592+
import fastapi
593+
except ImportError:
594+
raise utils.make_optional_import_error("fastapi")
595+
591596
message = await self._websocket.receive()
592-
if message.get("text"):
597+
598+
if message.get("type") == "websocket.disconnect":
599+
# NB(nikhil): Mimics FastAPI `_raise_on_disconnect`, since otherwise the user has no
600+
# way of detecting that the client disconnected.
601+
raise fastapi.WebSocketDisconnect(message["code"], message.get("reason"))
602+
elif message.get("text"):
593603
return typing.cast(str, message["text"])
594604
else:
595605
return typing.cast(bytes, message["bytes"])

truss/templates/control/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ loguru>=0.7.2
66
python-json-logger>=2.0.2
77
tenacity>=8.1.0
88
# To avoid divergence, this should follow the latest release.
9-
truss==0.11.1rc3
9+
truss==0.11.1rc15
1010
uvicorn>=0.24.0
1111
uvloop>=0.19.0
1212
websockets>=10.0

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)