Skip to content

Events Being Dropped on Connection#122

Merged
stephen-derosa merged 7 commits into
livekit:mainfrom
stephen-derosa:sderosa/BOT-344-bug-event-being-dropped
May 20, 2026
Merged

Events Being Dropped on Connection#122
stephen-derosa merged 7 commits into
livekit:mainfrom
stephen-derosa:sderosa/BOT-344-bug-event-being-dropped

Conversation

@stephen-derosa
Copy link
Copy Markdown
Collaborator

@stephen-derosa stephen-derosa commented May 9, 2026

Overview

  • Adds integration tests to validate events after connection
  • RoomReadyEventRequest which gets called after ffi handle is created

Testing

  • new integration test
  • manual addition of a sleep before the making the request shows that we still get the events

Comment thread .gitignore
Comment thread src/room.cpp Outdated
Comment thread src/tests/integration/test_late_join_track_publication.cpp Outdated
@stephen-derosa stephen-derosa force-pushed the sderosa/BOT-344-bug-event-being-dropped branch from 9b5a873 to edaf730 Compare May 11, 2026 19:31
Comment thread include/livekit/room.h Outdated
@stephen-derosa stephen-derosa force-pushed the sderosa/BOT-344-bug-event-being-dropped branch 7 times, most recently from cf3dcde to f0b82a9 Compare May 12, 2026 22:59
Copy link
Copy Markdown
Collaborator

@xianshijing-lk xianshijing-lk left a comment

Choose a reason for hiding this comment

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

lgtm.

can you search FfiClient::instance().AddListener() in our code base, and make sure we are using the same patter for all use cases ?

@stephen-derosa
Copy link
Copy Markdown
Collaborator Author

lgtm.

can you search FfiClient::instance().AddListener() in our code base, and make sure we are using the same patter for all use cases ?

@xianshijing-lk :
Done. The production call sites are Room, AudioStream, VideoStream, and DataTrackStream.
AudioStream and VideoStream already install their FFI listener before sending the FFI request that creates the stream, then remove it in close()/destruction. DataTrackStream receives an existing subscription handle, then installs the listener before read() starts requesting frames. Room now follows the same event-safety pattern by installing the listener before connectAsync(), and it removes the listener on failed Connect() so reconnect does not leave duplicate callbacks.
I didn’t find any other AddListener() usage that needs a matching change.

Comment thread src/tests/integration/test_late_join_track_publication.cpp Outdated
Comment thread src/tests/stress/test_room_listener_race_stress.cpp Outdated
Comment thread src/ffi_client.cpp
Comment thread src/room.cpp Outdated
@stephen-derosa stephen-derosa force-pushed the sderosa/BOT-344-bug-event-being-dropped branch from 597f291 to a3ee6a5 Compare May 13, 2026 20:05
@stephen-derosa
Copy link
Copy Markdown
Collaborator Author

new unit tests shows that the race condition does still exist. We are going to move forward with a "ready" signal from the client sdk to the rust sdk which signals to rust that the client is ready for room events. see this slack thread for discussion: https://live-kit.slack.com/archives/C02EWQYP4KE/p1778708015361339?thread_ts=1778285077.084319&cid=C02EWQYP4KE

@stephen-derosa stephen-derosa force-pushed the sderosa/BOT-344-bug-event-being-dropped branch 3 times, most recently from cb5f648 to 451d4ad Compare May 15, 2026 20:34
Copilot AI review requested due to automatic review settings May 20, 2026 00:44
@stephen-derosa stephen-derosa force-pushed the sderosa/BOT-344-bug-event-being-dropped branch from 451d4ad to f519e5f Compare May 20, 2026 00:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a connection-time race where room events can be dropped by registering the FFI event listener earlier in Room::Connect() and explicitly notifying the Rust core when the C++ room is ready to receive/flush room events. It also adds new integration/stress coverage focused on listener cleanup and late-join publication callbacks.

Changes:

  • Register the FFI listener before connectAsync() and send a new ready_for_room_event request after the room handle/state is fully initialized.
  • Add integration tests validating that failed/invalid connects and reconnect flows don’t leave duplicate listeners (no duplicate participant callbacks).
  • Add integration/stress tests validating late-join publication/subscription callback ordering and a concurrent reconnect/publish stress scenario.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/room.cpp Installs the FFI listener earlier and sends a “ready” request to flush room events once initialization completes; improves failure cleanup.
src/ffi_client.cpp Minor formatting cleanup.
src/tests/stress/test_room_listener_race_stress.cpp New stress test for concurrent failed connect/destroy/reconnect and data track publishing.
src/tests/integration/test_room_listener_cleanup.cpp New integration tests to ensure failed/invalid connects don’t leak/duplicate listeners and callbacks.
src/tests/integration/test_late_join_track_publication.cpp New parameterized integration tests validating late-join publication/subscription callback invariants for audio/video/data tracks.
AGENTS.md Adds guidance about not updating generated code (spelling nit present).
.gitignore Ignores user_stories.
Comments suppressed due to low confidence (2)

src/tests/integration/test_room_listener_cleanup.cpp:115

  • Tests should skip (GTEST_SKIP / skipIfNotConfigured) when LIVEKIT_* env vars are not set, rather than throwing. Throwing here will fail the entire integration test run in environments without credentials.
  if (!config_.available) {
    throw std::runtime_error("LIVEKIT_URL, LIVEKIT_TOKEN_A, and LIVEKIT_TOKEN_B not set");
  }

src/tests/integration/test_room_listener_cleanup.cpp:123

  • Tests should skip (GTEST_SKIP / skipIfNotConfigured) when LIVEKIT_* env vars are not set, rather than throwing. Throwing here will fail the entire integration test run in environments without credentials.
  if (!config_.available) {
    throw std::runtime_error("LIVEKIT_URL, LIVEKIT_TOKEN_A, and LIVEKIT_TOKEN_B not set");
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tests/stress/test_room_listener_race_stress.cpp
Comment thread src/tests/integration/test_room_listener_cleanup.cpp
Comment thread src/tests/integration/test_room_listener_cleanup.cpp Outdated
Comment thread src/tests/integration/test_late_join_track_publication.cpp Outdated
Comment thread src/tests/integration/test_late_join_track_publication.cpp
Comment thread AGENTS.md Outdated
@stephen-derosa stephen-derosa merged commit c8a2508 into livekit:main May 20, 2026
20 checks passed
@stephen-derosa stephen-derosa deleted the sderosa/BOT-344-bug-event-being-dropped branch May 20, 2026 17:53
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.

5 participants