From 009bb9dc710fe34376ff546050899e6320332457 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 29 Apr 2015 15:16:00 -0700 Subject: [PATCH] all 4 types of assignment-client appear to exit cleanly, now --- assignment-client/src/AssignmentClient.cpp | 8 ++++++++ assignment-client/src/AssignmentClientApp.cpp | 3 --- .../src/AssignmentClientMonitor.cpp | 2 ++ .../src/entities/EntityServer.cpp | 2 ++ assignment-client/src/octree/OctreeServer.cpp | 18 ++++++++++++++---- assignment-client/src/octree/OctreeServer.h | 3 +++ libraries/networking/src/LimitedNodeList.h | 4 +--- libraries/networking/src/NodeList.h | 5 +++++ libraries/shared/src/LogHandler.h | 6 ++++++ 9 files changed, 41 insertions(+), 10 deletions(-) diff --git a/assignment-client/src/AssignmentClient.cpp b/assignment-client/src/AssignmentClient.cpp index dc4d06e52e..4f00b30f42 100644 --- a/assignment-client/src/AssignmentClient.cpp +++ b/assignment-client/src/AssignmentClient.cpp @@ -126,7 +126,15 @@ void AssignmentClient::stopAssignmentClient() { void AssignmentClient::aboutToQuit() { + qDebug() << "AssignmentClient::aboutToQuit start"; stopAssignmentClient(); + qDebug() << "AssignmentClient::aboutToQuit end"; + // clear the log handler so that Qt doesn't call the destructor on LogHandler + qInstallMessageHandler(0); + // clear out pointer to the assignment so the destructor gets called. if we don't do this here, + // it will get destroyed along with all the other "static" stuff. various static member variables + // will be destroyed first and things go wrong. + _currentAssignment.clear(); } diff --git a/assignment-client/src/AssignmentClientApp.cpp b/assignment-client/src/AssignmentClientApp.cpp index c234daac68..d8e4306ec5 100644 --- a/assignment-client/src/AssignmentClientApp.cpp +++ b/assignment-client/src/AssignmentClientApp.cpp @@ -167,7 +167,6 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : } - if (parser.isSet(numChildsOption)) { if (minForks && minForks > numForks) { qCritical() << "--min can't be more than -n"; @@ -189,8 +188,6 @@ AssignmentClientApp::AssignmentClientApp(int argc, char* argv[]) : AssignmentClientMonitor monitor(numForks, minForks, maxForks, requestAssignmentType, assignmentPool, walletUUID, assignmentServerHostname, assignmentServerPort); connect(this, &QCoreApplication::aboutToQuit, &monitor, &AssignmentClientMonitor::aboutToQuit); - - exec(); } else { AssignmentClient client(ppid, requestAssignmentType, assignmentPool, diff --git a/assignment-client/src/AssignmentClientMonitor.cpp b/assignment-client/src/AssignmentClientMonitor.cpp index 14eb93ad6e..31743ea630 100644 --- a/assignment-client/src/AssignmentClientMonitor.cpp +++ b/assignment-client/src/AssignmentClientMonitor.cpp @@ -83,6 +83,8 @@ void AssignmentClientMonitor::stopChildProcesses() { void AssignmentClientMonitor::aboutToQuit() { stopChildProcesses(); + // clear the log handler so that Qt doesn't call the destructor on LogHandler + qInstallMessageHandler(0); } diff --git a/assignment-client/src/entities/EntityServer.cpp b/assignment-client/src/entities/EntityServer.cpp index b2a1c62ed4..a175eef475 100644 --- a/assignment-client/src/entities/EntityServer.cpp +++ b/assignment-client/src/entities/EntityServer.cpp @@ -163,3 +163,5 @@ void EntityServer::readAdditionalConfiguration(const QJsonObject& settingsSectio EntityTree* tree = static_cast(_tree); tree->setWantEditLogging(wantEditLogging); } + + diff --git a/assignment-client/src/octree/OctreeServer.cpp b/assignment-client/src/octree/OctreeServer.cpp index 506733e13d..11509192ad 100644 --- a/assignment-client/src/octree/OctreeServer.cpp +++ b/assignment-client/src/octree/OctreeServer.cpp @@ -239,8 +239,10 @@ OctreeServer::OctreeServer(const QByteArray& packet) : _octreeInboundPacketProcessor(NULL), _persistThread(NULL), _started(time(0)), - _startedUSecs(usecTimestampNow()) + _startedUSecs(usecTimestampNow()), + _nodeList(DependencyManager::get()) { + if (_instance) { qDebug() << "Octree Server starting... while old instance still running _instance=["<<_instance<<"] this=[" << this << "]"; } @@ -1098,7 +1100,7 @@ void OctreeServer::readConfiguration() { } void OctreeServer::run() { - qInstallMessageHandler(LogHandler::verboseMessageHandler); + // qInstallMessageHandler(LogHandler::verboseMessageHandler); _safeServerName = getMyServerName(); @@ -1222,8 +1224,15 @@ void OctreeServer::forceNodeShutdown(SharedNodePointer node) { void OctreeServer::aboutToFinish() { qDebug() << qPrintable(_safeServerName) << "server STARTING about to finish..."; qDebug() << qPrintable(_safeServerName) << "inform Octree Inbound Packet Processor that we are shutting down..."; - _octreeInboundPacketProcessor->terminating(); - + + if (_octreeInboundPacketProcessor) { + _octreeInboundPacketProcessor->terminating(); + } + + if (_jurisdictionSender) { + _jurisdictionSender->terminating(); + } + DependencyManager::get()->eachNode([this](const SharedNodePointer& node) { qDebug() << qPrintable(_safeServerName) << "server about to finish while node still connected node:" << *node; forceNodeShutdown(node); @@ -1231,6 +1240,7 @@ void OctreeServer::aboutToFinish() { if (_persistThread) { _persistThread->aboutToFinish(); + _persistThread->terminating(); } qDebug() << qPrintable(_safeServerName) << "server ENDING about to finish..."; diff --git a/assignment-client/src/octree/OctreeServer.h b/assignment-client/src/octree/OctreeServer.h index 41cd3259cf..09368fbe4d 100644 --- a/assignment-client/src/octree/OctreeServer.h +++ b/assignment-client/src/octree/OctreeServer.h @@ -238,6 +238,9 @@ protected: static QMutex _threadsDidPacketDistributorMutex; static QMutex _threadsDidHandlePacketSendMutex; static QMutex _threadsDidCallWriteDatagramMutex; + + // keep a pointer to node list so that it doesn't get shut down before this class. + QSharedPointer _nodeList; }; #endif // hifi_OctreeServer_h diff --git a/libraries/networking/src/LimitedNodeList.h b/libraries/networking/src/LimitedNodeList.h index cd45fbdbdf..f541a29d01 100644 --- a/libraries/networking/src/LimitedNodeList.h +++ b/libraries/networking/src/LimitedNodeList.h @@ -222,7 +222,7 @@ protected: LimitedNodeList(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton void operator=(LimitedNodeList const&); // Don't implement, needed to avoid copies of singleton - ~LimitedNodeList() { + virtual ~LimitedNodeList() { qDebug() << "XXXXXXXXXXXXXXXXXXXX ~LimitedNodeList called"; } @@ -241,8 +241,6 @@ protected: HifiSockAddr _localSockAddr; HifiSockAddr _publicSockAddr; HifiSockAddr _stunSockAddr; - - QTimer* _silentNodeTimer; // XXX can BandwidthRecorder be used for this? int _numCollectedPackets; diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index ccfaa7a4cf..4cb3fb8ea2 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -45,6 +45,11 @@ class NodeList : public LimitedNodeList { SINGLETON_DEPENDENCY public: + virtual ~NodeList() { + qDebug() << "XXXXXXXXXXXXXXXXXXXX ~NodeList called"; + } + + NodeType_t getOwnerType() const { return _ownerType; } void setOwnerType(NodeType_t ownerType) { _ownerType = ownerType; } diff --git a/libraries/shared/src/LogHandler.h b/libraries/shared/src/LogHandler.h index 914cad212d..1e9567b4d7 100644 --- a/libraries/shared/src/LogHandler.h +++ b/libraries/shared/src/LogHandler.h @@ -19,6 +19,8 @@ #include #include +#include + const int VERBOSE_LOG_INTERVAL_SECONDS = 5; enum LogMsgType { @@ -34,6 +36,10 @@ class LogHandler : public QObject { Q_OBJECT public: static LogHandler& getInstance(); + + virtual ~LogHandler() { + std::cerr << "XXXXXXXX ~LogHandler()\n"; + } /// sets the target name to output via the verboseMessageHandler, called once before logging begins /// \param targetName the desired target name to output in logs