QNetworkSession - register types before connecting slots

QNetworkSession's ctor has a race condition: it 1) connects signals/slots
and also 2) registers meta-types (but after these connects). Our users apparently
have a lot of per-thread QNAMs in multiple threads (and implicitly
many QNetworkSessions on different threads too). From error logs it appears
that while one thread tries to connect signals/slots and evaluates the types
of signal and slot arguments, another thread can register this type.
If the first thread extracted signal argument types, then the second
registered this type, we can end up in a 'type mismatch' error on the first
thread with seemingly the same types in a debug message (something like
"type mismatch A::Some <-> A::Some") - they have the same name, but one
has type() == 0 and another - some non-zero type().

Now we call qRegisterMetaType before connect.

Task-number: QTBUG-50901
Change-Id: Idbb9515573e174bbc5e5bf55dc3a7911a81646ea
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
Timur Pocheptsov 2017-02-15 09:43:45 +01:00
parent 1aaf45e106
commit de225ccdf9

View File

@ -252,6 +252,10 @@ QT_BEGIN_NAMESPACE
QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig, QObject *parent)
: QObject(parent), d(0)
{
qRegisterMetaType<QNetworkSession::State>();
qRegisterMetaType<QNetworkSession::SessionError>();
qRegisterMetaType<QNetworkSession::UsagePolicies>();
// invalid configuration
if (!connectionConfig.identifier().isEmpty()) {
const auto engines = qNetworkConfigurationManagerPrivate()->engines();
@ -277,10 +281,6 @@ QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig,
}
}
}
qRegisterMetaType<QNetworkSession::State>();
qRegisterMetaType<QNetworkSession::SessionError>();
qRegisterMetaType<QNetworkSession::UsagePolicies>();
}
/*!