Skip to content

Bugfix: Server-initiated room disconnect shutdown fix#205

Merged
alan-george-lk merged 22 commits into
mainfrom
alan/bugfix-room-shutdown
Jul 17, 2026
Merged

Bugfix: Server-initiated room disconnect shutdown fix#205
alan-george-lk merged 22 commits into
mainfrom
alan/bugfix-room-shutdown

Conversation

@alan-george-lk

@alan-george-lk alan-george-lk commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Fixes server-initiated room disconnect shutdown by routing explicit disconnect, destructor cleanup, server disconnect events, and EOS through a shared shutdown() helper, which by proxy cleans up event code
  • Ensure server Disconnected events remove the C++ FFI listener, stop subscriptions, clear room-owned state, and fire onDisconnected exactly once without re-sending an FFI disconnect

Before fix, when server deleted the room:

[2026-07-13 10:02:31.515] [livekit] [error] FfiClient listener threw: mutex lock failed: Invalid argument

Above observed on Mac, but crashed on Linux (user-reported). No longer after the fix.

Testing

  • Original issue reproduced via local binary (not committed), then fixed and confirmed no longer occurred
  • Add regression coverage for synthetic FFI server disconnects and local-SFU room deletion via lk --dev room delete
  • Consolidates emitFfiEvent into standalone header helper ffi_utils.h for use across two tests now

Ticket

BOT-464

@alan-george-lk alan-george-lk changed the title Bugfix: server-initiated room disconnect teardown fix Bugfix: Server-initiated room disconnect teardown fix Jul 13, 2026
@alan-george-lk
alan-george-lk marked this pull request as ready for review July 13, 2026 22:36

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

@xianshijing-lk xianshijing-lk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, assuming you address those comments.

Comment thread include/livekit/room.h Outdated
Comment thread src/room.cpp
Comment thread src/tests/unit/test_room.cpp Outdated
alan-george-lk and others added 2 commits July 13, 2026 21:53
Align the shared cleanup helper with LocalParticipant/FfiClient naming,
keep disconnect() returning false for no-ops per its documented contract,
and cover Room reuse after server-initiated shutdown.

Co-authored-by: Cursor <cursoragent@cursor.com>
@alan-george-lk alan-george-lk changed the title Bugfix: Server-initiated room disconnect teardown fix Bugfix: Server-initiated room disconnect shutdown fix Jul 14, 2026
devin-ai-integration[bot]

This comment was marked as resolved.

@xianshijing-lk

Copy link
Copy Markdown
Collaborator

lgtm, thanks

devin-ai-integration[bot]

This comment was marked as resolved.

Comment thread src/room.cpp

@stephen-derosa stephen-derosa left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice lgtm!

@alan-george-lk
alan-george-lk force-pushed the alan/bugfix-room-shutdown branch from 3cbddb6 to a2e6a9e Compare July 14, 2026 19:12
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@alan-george-lk
alan-george-lk merged commit ef35d9c into main Jul 17, 2026
25 checks passed
@alan-george-lk
alan-george-lk deleted the alan/bugfix-room-shutdown branch July 17, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants