When a session is shut down and the room is deleted shortly after it is initialized (via delete_room_on_close=True), three ERROR-level logs are emitted during teardown:
ERROR livekit::rtc_engine::rtc_session:646:livekit::rtc_engine::rtc_session - publisher data channel '_reliable' closed unexpectedly
ERROR livekit::rtc_engine::rtc_session:646:livekit::rtc_engine::rtc_session - publisher data channel '_lossy' closed unexpectedly
ERROR livekit::rtc_engine::rtc_session:646:livekit::rtc_engine::rtc_session - publisher data channel '_data_track' closed unexpectedly
They appear right after the framework deletes the room:
INFO deleting room on agent session close (disable via RoomInputOptions.delete_room_on_close=False)
ERROR ... publisher data channel '_reliable' closed unexpectedly
ERROR ... publisher data channel '_lossy' closed unexpectedly
ERROR ... publisher data channel '_data_track' closed unexpectedly
The call itself completes cleanly (shutdown callbacks run, post-call work succeeds). The data channels are closed because the room was deleted on purpose, so logging this at ERROR looks like a false positive during normal teardown.
Why it seems to happen
This appears to be a timing race during teardown: when ctx.shutdown() runs very early in the call, the room is deleted (server-side close of the data channels) before the session's local closed flag is set, so the new check at rtc_session.rs:646 (added in livekit/rust-sdks#1137) sees the channel close as unexpected. It is most reproducible when the session is shut down just a few seconds after the room is created.
Steps to reproduce
- Start an agent session.
- A few seconds after the room is initialized, call
ctx.shutdown() with delete_room_on_close=True (default).
- Observe the three
ERROR logs above during teardown.
Expected
A room deleted intentionally on session close should not log publisher data channel ... closed unexpectedly at ERROR level (e.g. suppress/downgrade when the close was initiated by us).
Versions
livekit-agents 1.6.4
livekit (rtc) 1.1.12
When a session is shut down and the room is deleted shortly after it is initialized (via
delete_room_on_close=True), threeERROR-level logs are emitted during teardown:They appear right after the framework deletes the room:
The call itself completes cleanly (shutdown callbacks run, post-call work succeeds). The data channels are closed because the room was deleted on purpose, so logging this at
ERRORlooks like a false positive during normal teardown.Why it seems to happen
This appears to be a timing race during teardown: when
ctx.shutdown()runs very early in the call, the room is deleted (server-side close of the data channels) before the session's localclosedflag is set, so the new check atrtc_session.rs:646(added in livekit/rust-sdks#1137) sees the channel close as unexpected. It is most reproducible when the session is shut down just a few seconds after the room is created.Steps to reproduce
ctx.shutdown()withdelete_room_on_close=True(default).ERRORlogs above during teardown.Expected
A room deleted intentionally on session close should not log
publisher data channel ... closed unexpectedlyatERRORlevel (e.g. suppress/downgrade when the close was initiated by us).Versions
livekit-agents1.6.4livekit(rtc) 1.1.12