Skip to content

bugfix:协程挂起不会创建新的webSocket#842

Merged
davidliu merged 2 commits intolivekit:mainfrom
CMzhizhe:fix_bug_timeout
Feb 16, 2026
Merged

bugfix:协程挂起不会创建新的webSocket#842
davidliu merged 2 commits intolivekit:mainfrom
CMzhizhe:fix_bug_timeout

Conversation

@CMzhizhe
Copy link
Copy Markdown
Contributor

private suspend fun connect(
        url: String,
        token: String,
        options: ConnectOptions,
        roomOptions: RoomOptions,
    ): Either<JoinResponse, Either<ReconnectResponse, Unit>> {
        // Clean up any pre-existing connection.
        close(reason = "Starting new connection", shouldClearQueuedRequests = false)
        .....  // If the connection to the server fails, the coroutine here will remain suspended.
        return suspendCancellableCoroutine {
            joinContinuation = it
            currentWs = websocketFactory.newWebSocket(request, this)
        }
    }

The inability to connect to the server will cause the coroutine to remain suspended and will not initiate a new connection.

Test steps
step1
Set a breakpoint in AlertDialog.Builder(), then wait 15 seconds to allow the room to reconnect.

binding.message.setOnClickListener {
            val editText = EditText(this)
            AlertDialog.Builder(this)
                .setTitle("Send Message")
                .setView(editText)
                .setPositiveButton("Send") { dialog, _ ->
                    viewModel.sendData(editText.text?.toString() ?: "")
                }
                .setNegativeButton("Cancel") { _, _ -> }
                .create()
                .show()
        }

step2
The code websocketFactory.newWebSocket(request, this) will be executed, but nothing will happen; no new connection will be initiated.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 24, 2025

⚠️ No Changeset found

Latest commit: 2af8be4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Dec 24, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown
Contributor

@davidliu davidliu left a comment

Choose a reason for hiding this comment

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

The timeout is unneeded here, as the websocket will call through to onFailure if it times out (default is 10 seconds). I'm going to remove this in a separate PR as it otherwise looks good to me.

@davidliu davidliu merged commit 20e8efd into livekit:main Feb 16, 2026
1 check passed
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.

3 participants