drop packets on floor when shutting down

This commit is contained in:
Stephen Birarda 2015-05-08 11:57:25 -07:00
parent fe1b8cc52b
commit 3d06a86670
5 changed files with 53 additions and 30 deletions

View file

@ -9,11 +9,15 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "PacketHeaders.h"
#include "SharedUtil.h"
#include "OctreeQueryNode.h"
#include <cstring>
#include <cstdio>
#include <PacketHeaders.h>
#include <SharedUtil.h>
#include <UUID.h>
#include "OctreeSendThread.h"
OctreeQueryNode::OctreeQueryNode() :

View file

@ -30,9 +30,14 @@ OctreeSendThread::OctreeSendThread(OctreeServer* myServer, const SharedNodePoint
_isShuttingDown(false)
{
QString safeServerName("Octree");
// set our QThread object name so we can identify this thread while debugging
setObjectName(QString("Octree Send Thread (%1)").arg(uuidStringWithoutCurlyBraces(node->getUUID())));
if (_myServer) {
safeServerName = _myServer->getMyServerName();
}
qDebug() << qPrintable(safeServerName) << "server [" << _myServer << "]: client connected "
"- starting sending thread [" << this << "]";

View file

@ -837,6 +837,10 @@ void OctreeServer::parsePayload() {
void OctreeServer::readPendingDatagram(const QByteArray& receivedPacket, const HifiSockAddr& senderSockAddr) {
auto nodeList = DependencyManager::get<NodeList>();
// If we know we're shutting down we just drop these packets on the floor.
// This stops us from initializing send threads we just shut down.
if (!_isShuttingDown) {
if (nodeList->packetVersionAndHashMatch(receivedPacket)) {
PacketType packetType = packetTypeForPacket(receivedPacket);
SharedNodePointer matchingNode = nodeList->sendingNodeForPacket(receivedPacket);
@ -845,6 +849,7 @@ void OctreeServer::readPendingDatagram(const QByteArray& receivedPacket, const H
// need to make sure we have it in our nodeList.
if (matchingNode) {
nodeList->updateNodeWithDataFromPacket(matchingNode, receivedPacket);
OctreeQueryNode* nodeData = (OctreeQueryNode*) matchingNode->getLinkedData();
if (nodeData && !nodeData->isOctreeSendThreadInitalized()) {
nodeData->initializeOctreeSendThread(this, matchingNode);
@ -869,6 +874,7 @@ void OctreeServer::readPendingDatagram(const QByteArray& receivedPacket, const H
}
}
}
}
void OctreeServer::setupDatagramProcessingThread() {
auto nodeList = DependencyManager::get<NodeList>();
@ -1214,6 +1220,9 @@ void OctreeServer::forceNodeShutdown(SharedNodePointer node) {
void OctreeServer::aboutToFinish() {
qDebug() << qPrintable(_safeServerName) << "server STARTING about to finish...";
_isShuttingDown = true;
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

View file

@ -152,6 +152,8 @@ protected:
char** _parsedArgV;
QJsonObject _settings;
bool _isShuttingDown = false;
HTTPManager* _httpManager;
int _statusPort;
QString _statusHost;

View file

@ -32,6 +32,9 @@ void GenericThread::initialize(bool isThreaded) {
if (_isThreaded) {
_thread = new QThread(this);
// match the thread name to our object name
_thread->setObjectName(objectName());
// when the worker thread is started, call our engine's run..
connect(_thread, SIGNAL(started()), this, SLOT(threadRoutine()));