livekit / client-sdk-android

LiveKit SDK for Android
https://docs.livekit.io
Apache License 2.0
176 stars 70 forks source link

End call crash (v1.1.4) #159

Open Arm63 opened 1 year ago

Arm63 commented 1 year ago

Describe the bug

On version, 1.1.4 try to end the call with the calling room.disconnect(), the crash is happens

Create room in ViewModel

    val audioHandler = AudioSwitchHandler(app)
    val room = LiveKit.create(
        appContext = app,
        options = RoomOptions(adaptiveStream = true, dynacast = true),
        overrides = LiveKitOverrides(
            audioHandler = audioHandler
        )
    )
  1. Start a call
  2. Waiting until UI is loaded
  3. End a call

    fun endCall(){
        viewModelScope.launch {
    
            val sessionId = getSessionCode() ?: return@launch
            val endSessionResponse = conferenceManager.stopLiveKitConference(sessionId)
    
            if (!endSessionResponse.success) return@launch
    
            disconnect()
        }
    }
    
       fun disconnect() {
        if (room.state != Room.State.DISCONNECTED) {
            room.disconnect()
        }
        state = CallState.IDLE
    }

    When I call stopLiveKitConference our server deletes the room and sends me a response of server call, after that I call the room.disconnect() and a crash happens. But when I call delay like 2000 before of room.dissconnect(), and all works normally without the crash.

Expected behavior Call must end

Device Info:

davidliu commented 1 year ago

Looks like there's a race condition here with the RTCEngine processing a leave message while Room.disconnect() is called. This might take some time to fix.

In the meantime, I think reversing the order might be a workaround (disconnecting the room object before deleting the room from the server).

benoitletondor commented 1 year ago

Hey, any news on that @davidliu ?

davidliu commented 1 year ago

Hey @benoitletondor, no news at the moment, I'll take another look at fixing this soon though.

shimika commented 1 year ago

Is it fixed in latest version? @davidliu

usayplz commented 1 year ago

have same bug, it happens when I try to execute room.disconnect immediately after I'v got Room.State.CONNECTED