Skip to content

Room.connect() throws fatal IllegalStateException instead of handling non-disconnected state gracefully #884

@indaos

Description

@indaos

Describe the bug
Calling Room.connect() on a room that is not in DISCONNECTED state throws an unrecoverable IllegalStateException, crashing the app. This can happen in legitimate reconnection scenarios where the server instructs the client to reconnect after a
network disruption. The SDK should handle this gracefully (e.g. by disconnecting first, queuing the connect, or returning an error) rather than throwing a fatal exception that crashes the host application.

java.lang.IllegalStateException: Room.connect attempted while room is not disconnected!
at io.livekit.android.room.Room$connect$2.invokeSuspend(Room.kt:389)

To Reproduce

  1. Connect to a LiveKit room successfully
  2. Trigger a network disconnection (e.g. airplane mode)
  3. Wait for the room to transition away from CONNECTED state
  4. Restore network and call Room.connect() again on the same room instance before it has fully transitioned to DISCONNECTED
  5. App crashes with IllegalStateException

Expected behavior
Room.connect() should not crash the application. If called on a non-disconnected room, it should either:

  • Disconnect the current session first and then proceed with the new connection, or
  • Return a meaningful error/exception that the caller can catch and handle, or
  • No-op if already connecting with the same parameters

Metadata

Metadata

Assignees

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