From a55c723842f69c21e94feffeac7b64b486aa2be8 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Thu, 6 Jun 2019 11:03:50 -0700 Subject: [PATCH 1/4] remove spammy logging --- libraries/networking/src/NodeList.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 3a896afe9b..038d656dbb 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -673,13 +673,6 @@ void NodeList::processDomainServerList(QSharedPointer message) // refuse to process this packet if we aren't currently connected to the DS return; } -#ifdef DEBUG_EVENT_QUEUE - { - int nodeListQueueSize = ::hifi::qt::getEventQueueSize(thread()); - qCDebug(networking) << "DomainList received, pending count =" << _domainHandler.getCheckInPacketsSinceLastReply() - << "NodeList thread event queue size =" << nodeListQueueSize; - } -#endif // warn if ping lag is getting long if (pingLagTime > qint64(MSECS_PER_SECOND)) { From d0bd4a7d479a529b3bdcda9fe961dad6c9cd0079 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Thu, 6 Jun 2019 14:01:34 -0700 Subject: [PATCH 2/4] try rebinding on error writing/reading from bound socket --- libraries/networking/src/udt/Socket.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 2867e83a1c..c73ac8109f 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -500,10 +500,18 @@ std::vector Socket::getConnectionSockAddrs() { void Socket::handleSocketError(QAbstractSocket::SocketError socketError) { qCDebug(networking) << "udt::Socket (" << _udpSocket.state() << ") error - " << socketError << "(" << _udpSocket.errorString() << ")"; +#ifdef WIN32 + int wsaError = WSAGetLastError(); + qCDebug(networking) << "windows socket error " << wsaError; +#endif #ifdef DEBUG_EVENT_QUEUE int nodeListQueueSize = ::hifi::qt::getEventQueueSize(thread()); qCDebug(networking) << "Networking queue size - " << nodeListQueueSize; #endif // DEBUG_EVENT_QUEUE + + if (_udpSocket.state() == QAbstractSocket::BoundState) { + rebind(); + } } void Socket::handleStateChanged(QAbstractSocket::SocketState socketState) { From 6643633400e2049c1699f84272985872fe8c4e14 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Fri, 7 Jun 2019 13:38:50 -0700 Subject: [PATCH 3/4] Move rebind on network error to rebind on silent domain checkin --- libraries/networking/src/NodeList.cpp | 6 ++++++ libraries/networking/src/udt/Socket.cpp | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 038d656dbb..0e6b5503d7 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -438,7 +438,13 @@ void NodeList::sendDomainServerCheckIn() { // Send duplicate check-ins in the exponentially increasing sequence 1, 1, 2, 4, ... static const int MAX_CHECKINS_TOGETHER = 20; + static const int REBIND_CHECKIN_COUNT = 2; int outstandingCheckins = _domainHandler.getCheckInPacketsSinceLastReply(); + + if (outstandingCheckins > REBIND_CHECKIN_COUNT) { + _nodeSocket.rebind(); + } + int checkinCount = outstandingCheckins > 1 ? std::pow(2, outstandingCheckins - 2) : 1; checkinCount = std::min(checkinCount, MAX_CHECKINS_TOGETHER); for (int i = 1; i < checkinCount; ++i) { diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index c73ac8109f..0abe1eb172 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -508,10 +508,6 @@ void Socket::handleSocketError(QAbstractSocket::SocketError socketError) { int nodeListQueueSize = ::hifi::qt::getEventQueueSize(thread()); qCDebug(networking) << "Networking queue size - " << nodeListQueueSize; #endif // DEBUG_EVENT_QUEUE - - if (_udpSocket.state() == QAbstractSocket::BoundState) { - rebind(); - } } void Socket::handleStateChanged(QAbstractSocket::SocketState socketState) { From ec1118db1fd26407c055d8e3956ae17303353a03 Mon Sep 17 00:00:00 2001 From: Roxanne Skelly Date: Fri, 7 Jun 2019 15:23:06 -0700 Subject: [PATCH 4/4] Attempting to write to a socket in unbound state was causing qt to crash after a number of tries. This fix does an initial check to prevent that case. --- libraries/networking/src/udt/Socket.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 0abe1eb172..406c2ff213 100644 --- a/libraries/networking/src/udt/Socket.cpp +++ b/libraries/networking/src/udt/Socket.cpp @@ -223,6 +223,13 @@ qint64 Socket::writeDatagram(const char* data, qint64 size, const HifiSockAddr& qint64 Socket::writeDatagram(const QByteArray& datagram, const HifiSockAddr& sockAddr) { + // don't attempt to write the datagram if we're unbound. Just drop it. + // _udpSocket.writeDatagram will return an error anyway, but there are + // potential crashes in Qt when that happens. + if (_udpSocket.state() != QAbstractSocket::BoundState) { + qCDebug(networking) << "Attempt to writeDatagram when in unbound state"; + return -1; + } qint64 bytesWritten = _udpSocket.writeDatagram(datagram, sockAddr.getAddress(), sockAddr.getPort()); if (bytesWritten < 0) {