Fix leaving room in one session causing call to be partially left in another session #7801
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.
Fixes a regression introduced in #6707 (specifically, in 802d1d2)
When the HPB is not used and the same conversation is joined in another tab a conflict response is returned by the internal signaling server* in the first tab, which causes a
duplicate-session-detectedevent to be triggered and this in turn causes a redirection to theduplicate-sessionpage.*If a long polling request fails with an internal error, for example if SQLite is used and the database is locked due to concurrent access, when the next polling gets again the session it will already use the session set by the second tab, so it will be the valid one and no conflict will be reported. But an internal error should not happen during the long polling, so this is such a corner case that, unless there is an easy fix, it should be fine to ignore, at least for now.
However, if the HPB is used there is no conflict response; in the past a
disinvitemessage was sent to the first session, which caused the UI to show a Conversation does not exist page (it should have shown the duplicated session page, but I do not know if that ever worked). However, thedisinvitemessage is no longer sent for registered users since 802d1d2. Due to that when the same conversation is joined in another tab the UI in the original one is still active, so further actions in the first tab mess with the session in the second tab. For example, if the conversation is switched in the first tab while the second tab is in a call the participant will leave the call and stay in it at the same time. To solve that, thedisinvitemessage is now sent again for regular users too, but only when removing a duplicated session.But, if the session of the second tab leaves the conversation, why was the call still active? The problem is the order in which the events are handled. When the conversation is left an event to leave the call is triggered, but the event is triggered once the conversation is left already. When the event is handled the session of the event is checked against the sessions in the conversation, but as the conversation was already left no session is found, so the message sent to the HPB is empty and therefore the HPB does not cause the call to be left.
To solve that now, when a conversation is left, if there is an active call it is first explicitly left and then the conversation is left. Note, however, that the RTCPeerConnections will be reconnected after some time, because the WebUI will try to leave the call but fail and, once the connection also fails, the handler to reconnect it will run despite no longer being in the call; that is fixed in #7799
The scenario 1 below can be tested only without the second commit, as the second commit fixes a precondition (being able to join the same conversation in another tab without leaving the conversation in the first tab). Nevertheless, even if the scenario 1 will no longer happen the first commit should still be applied.
How to test (scenario 1)
Result with first commit of this pull request
The call is left in the second tab
Note that without #7799 the connections will be established again after some time (even if the UI still appears as not in the call)
Result without this pull request
The call is not left in the second tab (although there is a chat message saying that you left the call)
How to test (scenario 2)
Result with this pull request
The conversation is left in the first tab
Note that no conflict warning is shown in the second tab because since #4374 this is done only when the previous session is in a call
Result without this pull request
The conversation is not left in the first tab