From c7affea41193c0ec4373f1e2cbe39810a99221ae Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 24 Aug 2017 16:40:16 -0700 Subject: [PATCH] add a timeout for ICE server DNS lookup --- domain-server/src/DomainServer.cpp | 19 ++++++++++++++++++- domain-server/src/DomainServer.h | 6 +++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/domain-server/src/DomainServer.cpp b/domain-server/src/DomainServer.cpp index 163bd48f1b..d9de9fe963 100644 --- a/domain-server/src/DomainServer.cpp +++ b/domain-server/src/DomainServer.cpp @@ -711,8 +711,25 @@ void DomainServer::setupICEHeartbeatForFullNetworking() { } void DomainServer::updateICEServerAddresses() { - if (_iceAddressLookupID == -1) { + if (_iceAddressLookupID == INVALID_ICE_LOOKUP_ID) { _iceAddressLookupID = QHostInfo::lookupHost(_iceServerAddr, this, SLOT(handleICEHostInfo(QHostInfo))); + + // there seems to be a 5.9 bug where lookupHost never calls our slot + // so we add a single shot manual "timeout" to fire it off again if it hasn't called back yet + static const int ICE_ADDRESS_LOOKUP_TIMEOUT_MS = 5000; + QTimer::singleShot(ICE_ADDRESS_LOOKUP_TIMEOUT_MS, this, &DomainServer::timeoutICEAddressLookup); + } +} + +void DomainServer::timeoutICEAddressLookup() { + if (_iceAddressLookupID != INVALID_ICE_LOOKUP_ID) { + // we waited 5s and didn't hear back for our ICE DNS lookup + // so time that one out and kick off another + QHostInfo::abortHostLookup(_iceAddressLookupID); + + _iceAddressLookupID = INVALID_ICE_LOOKUP_ID; + + updateICEServerAddresses(); } } diff --git a/domain-server/src/DomainServer.h b/domain-server/src/DomainServer.h index 4808297c89..ac57375407 100644 --- a/domain-server/src/DomainServer.h +++ b/domain-server/src/DomainServer.h @@ -39,6 +39,8 @@ typedef QMultiHash TransactionHash; using Subnet = QPair; using SubnetList = std::vector; +const int INVALID_ICE_LOOKUP_ID = -1; + enum ReplicationServerDirection { Upstream, Downstream @@ -114,6 +116,8 @@ private slots: void tokenGrantFinished(); void profileRequestFinished(); + void timeoutICEAddressLookup(); + signals: void iceServerChanged(); void userConnected(); @@ -223,7 +227,7 @@ private: QList _iceServerAddresses; QSet _failedIceServerAddresses; - int _iceAddressLookupID { -1 }; + int _iceAddressLookupID { INVALID_ICE_LOOKUP_ID }; int _noReplyICEHeartbeats { 0 }; int _numHeartbeatDenials { 0 }; bool _connectedToICEServer { false };