Skip to content

Commit 1fd34db

Browse files
Just avoid calling add_msg_to_stream if it should not be called
1 parent 897d2e0 commit 1fd34db

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

src/replit_river/client_session.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,15 @@ async def _handle_messages_from_ws(self) -> None:
144144
raise IgnoreMessageException(
145145
"no stream for message, ignoring"
146146
)
147-
await add_msg_to_stream(msg, stream)
147+
148+
if (
149+
msg.controlFlags & STREAM_CLOSED_BIT != 0
150+
and msg.payload.get("type", None) == "CLOSE"
151+
):
152+
# close message is not sent to the stream
153+
pass
154+
else:
155+
await add_msg_to_stream(msg, stream)
148156
else:
149157
raise InvalidMessageException(
150158
"Client should not receive stream open bit"

src/replit_river/common_session.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,6 @@ async def add_msg_to_stream(
119119
msg: TransportMessage,
120120
stream: Channel[Any],
121121
) -> None:
122-
if (
123-
msg.controlFlags & STREAM_CLOSED_BIT != 0
124-
and msg.payload.get("type", None) == "CLOSE"
125-
):
126-
# close message is not sent to the stream
127-
return
128122
try:
129123
await stream.put(msg.payload)
130124
except ChannelClosed:

src/replit_river/server_session.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,15 @@ async def _handle_messages_from_ws(self, tg: asyncio.TaskGroup) -> None:
143143
raise IgnoreMessageException(
144144
"no stream for message, ignoring"
145145
)
146-
await add_msg_to_stream(msg, stream)
146+
147+
if (
148+
msg.controlFlags & STREAM_CLOSED_BIT != 0
149+
and msg.payload.get("type", None) == "CLOSE"
150+
):
151+
# close message is not sent to the stream
152+
pass
153+
else:
154+
await add_msg_to_stream(msg, stream)
147155
else:
148156
_stream = await self._open_stream_and_call_handler(msg, tg)
149157
if not stream:

src/replit_river/v2/client_session.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,15 @@ async def _handle_messages_from_ws(self) -> None:
140140
raise IgnoreMessageException(
141141
"no stream for message, ignoring"
142142
)
143-
await add_msg_to_stream(msg, stream)
143+
144+
if (
145+
msg.controlFlags & STREAM_CLOSED_BIT != 0
146+
and msg.payload.get("type", None) == "CLOSE"
147+
):
148+
# close message is not sent to the stream
149+
pass
150+
else:
151+
await add_msg_to_stream(msg, stream)
144152
else:
145153
raise InvalidMessageException(
146154
"Client should not receive stream open bit"

0 commit comments

Comments
 (0)