diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 3a896afe9b..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) { @@ -673,13 +679,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)) { diff --git a/libraries/networking/src/udt/Socket.cpp b/libraries/networking/src/udt/Socket.cpp index 2867e83a1c..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) { @@ -500,6 +507,10 @@ 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;