Skip to content

Room::disconnect() blocks and triggers reconnect/crash when offline #222

Description

@tomakor549

LiveKit C++ SDK Version

v1.4.0

Platform

Linux x86_64

OS Version

Ubuntu 26

Compiler & Version

g++ 15.2.0

CMake Version

4.2.3

How are you using the SDK?

Building from source (build.sh / build.cmd)

Issue Description

Calling Room::disconnect(DisconnectReason::ClientInitiated) while the network is down blocks the calling thread. When connectivity returns, internal rtc_engine attempts reconnect, fails with StateMismatch, and the process can crash.

shutdown function part:

void LiveKitService::shutdown() {
//...
qCInfo(LiveKitLog) << "_livekit_audio_source.reset()...";
_livekit_audio_source.reset();
qCInfo(LiveKitLog) << "_livekit_video_source.reset()...";
_livekit_video_source.reset();
qCInfo(LiveKitLog) << "_delegate.reset()...";
_delegate.reset();

if (_livekit_initialized.exchange(false)) {
qCInfo(LiveKitLog) << "_room.disconnect...";
_room.disconnect(DisconnectReason::ClientInitiated);
}
}

Steps to Reproduce

  1. Connect to a LiveKit room
  2. Disable network (or unplug)
  3. Call _room.disconnect(DisconnectReason::ClientInitiated)
  4. Observe: thread blocks
  5. Re-enable network
  6. Disconnect unblocks, then reconnect errors appear; crash may follow

Logs

##Example LOGS
[2026-07-28 19:22:34.077][LiveKitLog][INFO][53865][livekit::LiveKitService::shutdown:165]: _room.disconnect...
[2026-07-28T17:22:49Z ERROR livekit_api::signal_client::signal_stream] unhandled websocket message Err(Io(Os { code: 104, kind: ConnectionReset, message: "Connection reset by peer" }))
[2026-07-28T17:22:49Z ERROR livekit::rtc_engine] resuming connection failed: signal failure: server sent leave during reconnect: reason=StateMismatch, action=Reconnect
[2026-07-28T17:22:49Z ERROR livekit::rtc_engine] failed to reconnect to the livekit room
19:22:50: The command "..." terminated abnormally.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions