Skip to content

Error: Failed to set remote answer sdp: Called in wrong state: stable triggers unexpected unpublish events #755

@fede987

Description

@fede987

Description

When using the LiveKit Android SDK, an error is encountered intermittently, though often, when setting the remote description.

The LiveKit server is deployed on a custom machine, not using LiveKit Cloud.

The use case is always between 2 participants, A anb B.

Right after A and B enter the room their own audio and video tracks are published and subscribed by each other.
Then error encountered is the one that follows here:

RTCEngine$onAnswer: error setting remote description for answer: Failed to set remote answer sdp: Called in wrong state: stable

When this occurs for the user A, B participant client also receives an unexpected unpublish event from the remote participant. The behavior appears random and is difficult to reproduce reliably.

Expected Behavior

  • setRemoteDescription succeeds when negotiation flow is correct.
  • No unexpected unpublish events are emitted as a side effect.
  • Some API to recover from the error by allowing the re-publish of the tracks

Actual Behavior

  • During join or track negotiation, the SDK logs the error above.
  • Immediately after, the SDK emits an unpublish event for tracks that were previously published/visible.

Steps to Reproduce

This is intermittent; examples of flows where it has occurred:

  1. A and B join a room.
  2. A and B publish their own audio and video and the audio and video are then subscrbed correctly.
  3. Few seconds after, the local A participant SDK logs the error and the B participants receives an unpublish event.

Environment

  • SDK: LiveKit Android SDK
  • SDK Version: v2.20.1
  • Android Version: Occurring on all versions from 11 to 15
  • Devices: Oppo X3 neo, Xiaomi Pocophone f5 pro, various Android emulators
  • Network Conditions: stable wi-fi connection

Logs / Stacktrace (from user A)

2025-09-05 15:30:59.765 23421-14241 RTCModule$...ialization com.xxxx.xxxx V webrtc_sdp.cc: (line 3335): Ignoring send_rids without simulcast
2025-09-05 15:30:59.765 23421-14798 RTCModule$...ialization com.xxxx.xxxx E sdp_offer_answer.cc: (line 3759): Called in wrong state: stable (INVALID_STATE)
2025-09-05 15:30:59.765 23421-14798 RTCModule$...ialization com.xxxx.xxxx E sdp_offer_answer.cc: (line 993): Failed to set remote answer sdp: Called in wrong state: stable
2025-09-05 15:30:59.766 23421-14134 RTCEngine com.xxxx.xxxx V received ice candidate from peer: 0:0:candidate:2363694099 1 tcp 1671430143 172.31.120.190 7881 typ host tcptype passive ufrag dOjamyXyvoyHKouk::UNKNOWN, PUBLISHER
2025-09-05 15:30:59.766 23421-14916 SignalClient com.xxxx.xxxx V response: # livekit.LivekitRtc$SignalResponse@eb1a8d1d
trickle {
candidate_init: "{"candidate":"candidate:2371725571 1 udp 2130706431 54.194.75.113 59410 typ host ufrag GLTaUtjrPxKmaysS","sdpMid":"1","sdpMLineIndex":0,"usernameFragment":null}"
}
2025-09-05 15:30:59.767 23421-14330 RTCEngine$onAnswer com.xxxx.xxxx E error setting remote description for answer: Failed to set remote answer sdp: Called in wrong state: stable

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