diff options
author | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2017-02-15 09:43:45 +0100 |
---|---|---|
committer | Timur Pocheptsov <timur.pocheptsov@qt.io> | 2017-02-16 15:52:42 +0000 |
commit | de225ccdf95efb57866d62bc80872c1a2ab99703 (patch) | |
tree | 8f394781d150ab76680c0d56e048a3ceb2b3973f /src/network | |
parent | 1aaf45e10680242511c047d84ec4f1c9a86cda7f (diff) | |
download | qtbase-de225ccdf95efb57866d62bc80872c1a2ab99703.tar.gz |
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>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/bearer/qnetworksession.cpp | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 2ad46918b2..bbcd191041 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -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>(); } /*! |