Skip to content

Commit

Permalink
Fix a race when switching rooms at different accounts
Browse files Browse the repository at this point in the history
That atomic pointer to Connection in ThumbnailProvider was never enough
to protect against the old connection being used with the new current
room, or vice versa because of a too early, or too late, request for
an avatar from QML around the moment of switching to the new room.

This commit introduces an interim null room state in
MessageEventMode::changeRoom() - this way, the old QML objects have no
chance to issue requests over the connection that already got updated;
and new QML objects only come to exist when the connection is set to
the new value.
  • Loading branch information
Kitsune Ral committed Dec 25, 2023
1 parent c074213 commit 4ce59f7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions client/models/messageeventmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ MessageEventModel::MessageEventModel(QObject* parent)
// connection to modelReset. Ideally the room property could use modelReset
// for its NOTIFY signal - unfortunately, moc doesn't support using
// parent's signals with parameters in NOTIFY
// NB: this makes all roomChanged connections order before modelReset
// connections
connect(this, &MessageEventModel::modelReset, //
this, &MessageEventModel::roomChanged);
}
Expand All @@ -83,13 +85,18 @@ void MessageEventModel::changeRoom(QuaternionRoom* room)
if (room == m_currentRoom)
return;

if (m_currentRoom)
if (m_currentRoom) {
qCDebug(EVENTMODEL)
<< "Disconnecting event model from" << m_currentRoom->objectName();
beginResetModel();
if (m_currentRoom)
// Reset the model to a null room first to make sure QML dismantles
// last room's objects before the room is actually changed
beginResetModel();
m_currentRoom->disconnect(this);
m_currentRoom = nullptr;
endResetModel();
}

beginResetModel();
m_currentRoom = room;
if (m_currentRoom) {
using namespace Quotient;
Expand Down

0 comments on commit 4ce59f7

Please sign in to comment.