Skip to content

Room destructor does not disconnect from server; shutdown() must be called first (undocumented requirement) #118

@Soralsei

Description

@Soralsei

Summary

Destroying a Room object (via room.reset() or end of scope) does not send a disconnect signal to the LiveKit server.

Root cause

~Room() calls ~FfiHandle()livekit_ffi_drop_handle(), which only removes the handle from FFI_SERVER.ffi_handles. It does not close the room.

livekit_ffi_dispose() (called by livekit::shutdown()) is what actually iterates ffi_handles and calls room.close(ClientInitiated) — but only for handles still in the map at that point.

So the following common pattern silently fails to disconnect:

room.reset();       // drops handle → removed from ffi_handles
livekit::shutdown(); // dispose() finds no rooms → never sends disconnect

Correct Order with current implementation

livekit::shutdown(); // dispose() finds room in ffi_handles → room.close() → server notified
room.reset();        // C++ wrapper destroyed; FFI handle already gone

This is neither documented nor enforced, and contradicts natural RAII expectations (object destruction is sufficient for cleanup).

Expected behavior

One of:

  • Option A: ~Room() sends an explicit DisconnectRequest before dropping the FFI handle, making destruction sufficient for a clean leave.
  • Option B: A public Room::disconnect() method is added with documentation requiring it before destruction.
  • Option C: Document the required shutdown()-before-reset() ordering in the quickstart guide and in room.h if possible.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions