Skip to content

Connection instability when receiving and sending data messages immediately after joining a room #721

@Christophe-DC

Description

@Christophe-DC

Describe the bug
Just after connecting to a room with LiveKit.connect(...), I immediately receive a data message via onDataReceived.
In response to this message, I send a reply using room.localParticipant.publishData(...).
Sometimes, the message is never sent, and I get the following exception:
RoomException$ConnectException: could not establish publisher connection
This seems to be a race condition: although the room is connected and I receive data, the publisher's PeerConnection is not yet fully established.

To Reproduce
Steps to reproduce the behavior:

  1. Call LiveKit.connect(...).
  2. Receive a data message immediately after joining (via onDataReceived).
  3. In the same flow, send a reply with publishData(...).
  4. Observe that the message is sometimes: never received by remote participants

Expected behavior
Messages sent with publishData(...) should be reliably sent once the room is connected.
Receiving a message should indicate that connections are ready, or at least not give a false sense of readiness.
Ideally, the SDK should:
buffer the message until the publisher is connected, or expose a clear lifecycle signal that the publisher is ready to send.

Screenshots
If applicable, add screenshots to help explain your problem.

Device Info:

  • Device: Google Pixel 7, Samsung A52
  • OS: Android 15
  • LiveKit SDK version: 2.18.2

Additional context
livekit-logs.txt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions