Make QDBusConnectionPrivate::relaySignal be called in the right thread

This function sends D-Bus messages directly (in huntAndEmit), so it
should only be called from the QDBusConnectionManager thread. Somehow, I
missed this in the Qt 5.6 refactoring of QtDBus.

Being called in the wrong thread means that there's a visible behavior
change compared to Qt 5.5: if the user code sent a method call or method
return/error and then emitted a signal, we'd have two threads racing to
send the D-Bus messages. This was observed in Telepathy-Qt code: certain
signals arrived before a method return, even though they were clearly
emitted by a queued QMetaObject::invokeMethod.

In addition to that, we have has an internal problem (though not
observed): the libdbus-1 timer and socket callbacks would be called in
the wrong thread and we no longer have protection against that.

Unit testing not possible since this is a race condition.

Change-Id: I9e96ecd4f6aa4ff0ae08fffd1471d002142613d6
Reviewed-by: Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
Thiago Macieira 2016-09-06 11:41:00 -07:00
parent 469d68b344
commit ebf0b12108

View File

@ -1257,6 +1257,7 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in
break;
}
checkThread();
QDBusReadLocker locker(RelaySignalAction, this);
QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/"), interface,
QLatin1String(memberName));
@ -2368,12 +2369,9 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
connector->connectAllSignals(node->obj);
}
// disconnect and reconnect to avoid duplicates
connector->disconnect(SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)));
connect(connector, SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
Qt::DirectConnection);
Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection));
}
}