From 0f71e93c7f95197362ea736d9c22af45349e810d Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 8 May 2015 10:12:14 -0700 Subject: [PATCH] ensure no new OST creation on OctreeServer shutdown --- assignment-client/src/octree/OctreeServer.cpp | 9 ++++++++- libraries/networking/src/NodeList.cpp | 5 ++++- libraries/networking/src/ThreadedAssignment.cpp | 11 ++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index b994443b83..41b46c0947 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -1216,6 +1216,11 @@ void OctreeServer::aboutToFinish() { qDebug() << qPrintable(_safeServerName) << "server STARTING about to finish..."; qDebug() << qPrintable(_safeServerName) << "inform Octree Inbound Packet Processor that we are shutting down..."; + // we're going down - set the NodeList linkedDataCallback to NULL so we do not create any more OctreeSendThreads + // this ensures that when we forceNodeShutdown below for each node we don't get any more newly connecting nodes + auto nodeList = DependencyManager::get(); + nodeList->linkedDataCreateCallback = NULL; + if (_octreeInboundPacketProcessor) { _octreeInboundPacketProcessor->terminating(); } @@ -1224,7 +1229,9 @@ void OctreeServer::aboutToFinish() { _jurisdictionSender->terminating(); } - DependencyManager::get()->eachNode([this](const SharedNodePointer& node) { + // force a shutdown of all of our OctreeSendThreads - at this point it has to be impossible for a + // linkedDataCreateCallback to be called for a new node + nodeList->eachNode([this](const SharedNodePointer& node) { qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *node; forceNodeShutdown(node); }); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 819c46cdf0..b30afb91de 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -150,7 +150,10 @@ void NodeList::timePingReply(const QByteArray& packet, const SharedNodePointer& void NodeList::processNodeData(const HifiSockAddr& senderSockAddr, const QByteArray& packet) { switch (packetTypeForPacket(packet)) { case PacketTypeDomainList: { - processDomainServerList(packet); + if (_domainHandler.isConnected()) { + // only process a list from domain-server if we think we're connected + processDomainServerList(packet); + } break; } case PacketTypeDomainServerRequireDTLS: { diff --git a/libraries/networking/src/ThreadedAssignment.cpp b/libraries/networking/src/ThreadedAssignment.cpp index ee608411ca..f2b4018495 100644 --- a/libraries/networking/src/ThreadedAssignment.cpp +++ b/libraries/networking/src/ThreadedAssignment.cpp @@ -41,16 +41,21 @@ void ThreadedAssignment::setFinished(bool isFinished) { if (_statsTimer) { _statsTimer->stop(); } - - aboutToFinish(); + // stop processing datagrams from the node socket + // this ensures we won't process a domain list while we are going down auto nodeList = DependencyManager::get(); + disconnect(&nodeList->getNodeSocket(), 0, this, 0); + + // call our virtual aboutToFinish method - this gives the ThreadedAssignment subclass a chance to cleanup + aboutToFinish(); // if we have a datagram processing thread, quit it and wait on it to make sure that // the node socket is back on the same thread as the NodeList if (_datagramProcessingThread) { - // tell the datagram processing thread to quit and wait until it is done, then return the node socket to the NodeList + // tell the datagram processing thread to quit and wait until it is done, + // then return the node socket to the NodeList _datagramProcessingThread->quit(); _datagramProcessingThread->wait();