8000 Fix raceconditions in the client by Krzmbrzl · Pull Request #4430 · mumble-voip/mumble · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix raceconditions in the client #4430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Krzmbrzl
Copy link
Member

This PR fixes 2 raceconditions that both occur due to the MainWindow::serverDisconnected being able to trigger while certain client-server communication is still happening (unfinished).

The effects of these are

  1. Loss of server-specific shortcuts due to them being saved from emory before having been loaded into it in the first place (due to msgServerSync not having been called yet)
  2. Loss of ChannelListeners due to them being saved before their synchronisation with the server being done (and therefore again not having been loaded into memory yet but being saved from there).

Below are some notes of what exactly is happening for 1) to happen. The cause for 2) is rather similar and should be understandable from the commit-message.

- serverConnectionConnected is called as soon as the QSslSocket emits the encrypted() signal (probably after TLS handshake); This represents the
  "Connect" step in the image at https://mumble-protocol.readthedocs.io/en/latest/establishing_connection.html#connect
- Inside ServerHandler::serverConnectionConnected the Version message is sent to the server and after that the Authenticate message is also sent
- At the end of serverConnectionConnected the "connected" signal is emitted
- As soon as the QSslConnection is interrupted, the "disconncted" signal is emitted

- The sever-specfic shortcuts are loaded in MainWindow::msgServerSync
- The ServerSync message is only sent by the server as soon as the Authenticate message has been received and processed (and the actual
  synchronization has happened).

- MainWindow::serverDisconnected stores the server-specific shortcuts that are stored in memory into the database
- If the shortcuts haven't been loaded yet, there are no shortcuts in memory and thus the shortcuts in the database are cleared


If the SSL connection is interrupted (or terminated?) before the client has received the ServerSync message from the server, the serverDisconnected
function runs before the msgServerSync function (which won't run at all) and thus the shortcuts are saved from memory into the database without having
been loaded from the database into memory in the first place.

To avoid this the shortcuts (and ChannelListeners) must not be saved unless synchronization with the server has happened before.

@Krzmbrzl Krzmbrzl added client backport-needed bug A bug (error) in the software labels Aug 19, 2020
Krzmbrzl added a commit to Krzmbrzl/mumble that referenced this pull request Aug 19, 2020
Server-specific shortcuts are read into memory in
MainWindow::msgServerSync and are saved into the DB again in
MainWindow::serverDisconnected.
If however the disconnect function runs before the server
synchronization has finished, the shortcut list in memory is empty and
by writing that into the DB all existing server-specific shortcuts are
lost (overwritten).

This commit adds checks before saving the shortcuts so that saving only
occurs if the synchronization has happened before and thus the
shortcuts have been loaded in the first place.

(Backported from mumble-voip#4430 and adapted to work with the 1.3.x series)
Krzmbrzl added a commit to Krzmbrzl/mumble that referenced this pull request Aug 19, 2020
Server-specific shortcuts are read into memory in
MainWindow::msgServerSync and are saved into the DB again in
MainWindow::serverDisconnected.
If however the disconnect function runs before the server
synchronization has finished, the shortcut list in memory is empty and
by writing that into the DB all existing server-specific shortcuts are
lost (overwritten).

This commit adds checks before saving the shortcuts so that saving only
occurs if the synchronization has happened before and thus the
shortcuts have been loaded in the first place.

(Backported from mumble-voip#4430 and adapted to work with the 1.3.x series)
@Krzmbrzl Krzmbrzl force-pushed the fix-shortcutsLostDueToRaceCondition branch from 9bbcd83 to 043eeae Compare August 19, 2020 14:53
Copy link
Member
@davidebeatrici davidebeatrici left a comment

Choose a reason for hiding this comment

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

Looks good to me.

I assume you prefer "synchronization" rather than "sinchronisation" because you used it the most.

My browser's dictionary and I agree with you!

Server-specific shortcuts are read into memory in
MainWindow::msgServerSync and are saved into the DB again in
MainWindow::serverDisconnected.
If however the disconnect function runs before the server
synchronization has finished, the shortcut list in memory is empty and
by writing that into the DB all existing server-specific shortcuts are
lost (overwritten).

This commit adds checks before saving the shortcuts (and
ChannelListeners) so that saving only occurs if the synchronization has
happened before and thus the shortcuts have been loaded in the first
place.
As ChannelListeners are only synchronised with the server once
msgServerSync has been received, there is still a racecondition for them
even though we only save them if the ServerSync has happened yet.
The connection could be terminated before the answer of the server for
the request to add the respective listeners reaches the client. In that
case the listeners would be erased by the call to
ChannelListener::saveToDB().

Thus this commit introduces yet another flag indicating whether the
listeners have synchronised with the server yet.
The processing of ChannelListeners was delayed until the next iteration
of the Qt event loop since it was thought that msgServerSync was running
in another thread. Given that this function already accesses the DB,
this can't be though.

Thus the delay is unnecessary and was therefore removed.
@Krzmbrzl Krzmbrzl force-pushed the fix-shortcutsLostDueToRaceCondition branch from 043eeae to ba06bb1 Compare August 21, 2020 09:32
@Krzmbrzl Krzmbrzl merged commit 0e6e36d into mumble-voip:master Aug 21, 2020
Krzmbrzl added a commit that referenced this pull request Aug 21, 2020
@Krzmbrzl Krzmbrzl deleted the fix-shortcutsLostDueToRaceCondition branch November 9, 2022 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug (error) in the software client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0