Always emit Disconnected on engine close#1096
Merged
Merged
Conversation
`RtcEngineInner::close` only emitted `EngineEvent::Disconnected` from inside the `if let Some(engine_task)` block. Each failed `try_restart_connection` calls `running_handle.engine_task.take()` and does not restore it on error, so after the reconnect loop exhausts all attempts and calls `close(UnknownReason)`, `engine_task` is already `None` and the disconnect event is never sent. The room task never runs `handle_disconnected`, the connection state stays at Reconnecting, and `RoomEvent::Disconnected` is never dispatched — consumers see the room appear permanently stuck in reconnect after a network outage. Move the emit outside the if-let so the event always fires on close. Duplicates are absorbed by `update_connection_state` on the room side.
Contributor
ChangesetThe following package versions will be affected by this PR:
|
xianshijing-lk
approved these changes
May 18, 2026
| // prior failed `try_restart_connection`. Without this, a reconnect cycle that | ||
| // exhausts all attempts leaves the room stuck in Reconnecting forever because | ||
| // the room's task never sees the event that drives `handle_disconnected`. | ||
| let _ = self.engine_tx.send(EngineEvent::Disconnected { reason }); |
Contributor
There was a problem hiding this comment.
any chance that there could be duplicated disconnected events ?
what will happen if close() is called multiple times ?
Contributor
|
I'm OK with this quick fix for now, but we should review the connection state machine more carefully. |
Contributor
Author
Lets do that, saw your post on Slack and I also think this is the right way if we can spend the time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
RtcEngineInner::closeonly emittedEngineEvent::Disconnectedfrom inside theif let Some(engine_task)block. Each failedtry_restart_connectioncallsrunning_handle.engine_task.take()and does not restore it on error, so after the reconnect loop exhausts all attempts and callsclose(UnknownReason),engine_taskis alreadyNoneand the disconnect event is never sent. The room task never runshandle_disconnected, the connection state stays at Reconnecting, andRoomEvent::Disconnectedis never dispatched — consumers see the room appear permanently stuck in reconnect after a network outage.Repro
Use Unity SDK Meet sample and lock the screen. Android will remove network access to the app and it will try 10 reconnects, until it fails eventually. In browser I can observe the Android participant being removed.
Unlock Android phone again and without the fix, I did not receive a Room.OnDisconnected event, the state is still
Reconnectingand not disconnected.Changes
Move the emit outside the if-let so the event always fires on close. Duplicates are absorbed by
update_connection_stateon the room side.