Skip to content

Commit f8a4d93

Browse files
committed
check in aclose
1 parent b333bd0 commit f8a4d93

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

livekit-rtc/livekit/rtc/data_stream.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ async def _send_chunk(self, chunk: proto_DataStream.Chunk):
217217
raise ConnectionError(cb.send_stream_chunk.error)
218218

219219
async def _send_trailer(self, trailer: proto_DataStream.Trailer):
220-
if self._closed:
221-
raise RuntimeError(f"Cannot send trailer after stream is closed: {trailer}")
222220
req = proto_ffi.FfiRequest(
223221
send_stream_trailer=proto_room.SendStreamTrailerRequest(
224222
trailer=trailer,
@@ -240,11 +238,12 @@ async def _send_trailer(self, trailer: proto_DataStream.Trailer):
240238
if cb.send_stream_chunk.error:
241239
raise ConnectionError(cb.send_stream_trailer.error)
242240

243-
self._closed = True
244-
245241
async def aclose(
246242
self, *, reason: str = "", attributes: Optional[Dict[str, str]] = None
247243
):
244+
if self._closed:
245+
raise RuntimeError("Stream already closed")
246+
self._closed = True
248247
await self._send_trailer(
249248
trailer=proto_DataStream.Trailer(
250249
stream_id=self._header.stream_id, reason=reason, attributes=attributes

0 commit comments

Comments
 (0)