Merge pull request #11810 from Atlante45/fix/stuck-acs

Fix stuck ACs
This commit is contained in:
Ryan Huffman 2017-11-15 14:59:51 -08:00 committed by GitHub
commit 60a222e4b4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 7 deletions

View file

@ -28,6 +28,10 @@
const QString ASSIGNMENT_CLIENT_MONITOR_TARGET_NAME = "assignment-client-monitor";
const int WAIT_FOR_CHILD_MSECS = 1000;
#ifdef Q_OS_WIN
HANDLE PROCESS_GROUP = createProcessGroup();
#endif
AssignmentClientMonitor::AssignmentClientMonitor(const unsigned int numAssignmentClientForks,
const unsigned int minAssignmentClientForks,
const unsigned int maxAssignmentClientForks,
@ -202,6 +206,10 @@ void AssignmentClientMonitor::spawnChildClient() {
assignmentClient->setProcessChannelMode(QProcess::ForwardedChannels);
assignmentClient->start(QCoreApplication::applicationFilePath(), _childArguments);
#ifdef Q_OS_WIN
addProcessToGroup(PROCESS_GROUP, assignmentClient->processId());
#endif
QString stdoutPath, stderrPath;
if (_wantsChildFileLogging) {

View file

@ -1700,8 +1700,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
lastLeftHandPose = leftHandPose;
lastRightHandPose = rightHandPose;
properties["local_socket_changes"] = DependencyManager::get<StatTracker>()->getStat(LOCAL_SOCKET_CHANGE_STAT).toInt();
UserActivityLogger::getInstance().logAction("stats", properties);
});
sendStatsTimer->start();

View file

@ -27,7 +27,6 @@
#include <NumericalConstants.h>
#include <SettingHandle.h>
#include <SharedUtil.h>
#include <StatTracker.h>
#include <UUID.h>
#include "AccountManager.h"
@ -1110,7 +1109,6 @@ void LimitedNodeList::setLocalSocket(const HifiSockAddr& sockAddr) {
qCInfo(networking) << "Local socket is" << sockAddr;
} else {
qCInfo(networking) << "Local socket has changed from" << _localSockAddr << "to" << sockAddr;
DependencyManager::get<StatTracker>()->incrementStat(LOCAL_SOCKET_CHANGE_STAT);
}
_localSockAddr = sockAddr;

View file

@ -66,8 +66,6 @@ const QHostAddress DEFAULT_ASSIGNMENT_CLIENT_MONITOR_HOSTNAME = QHostAddress::Lo
const QString USERNAME_UUID_REPLACEMENT_STATS_KEY = "$username";
const QString LOCAL_SOCKET_CHANGE_STAT = "LocalSocketChanges";
typedef std::pair<QUuid, SharedNodePointer> UUIDNodePair;
typedef tbb::concurrent_unordered_map<QUuid, SharedNodePointer, UUIDHasher> NodeHash;

View file

@ -1081,7 +1081,7 @@ void setMaxCores(uint8_t maxCores) {
void quitWithParentProcess() {
if (qApp) {
qDebug() << "Parent process died, quitting";
qApp->quit();
exit(0);
}
}
@ -1113,3 +1113,57 @@ void watchParentProcess(int parentPID) {
timer->start();
}
#endif
#ifdef Q_OS_WIN
QString getLastErrorAsString() {
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0) {
return QString();
}
LPSTR messageBuffer = nullptr;
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
nullptr, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, nullptr);
auto message = QString::fromLocal8Bit(messageBuffer, (int)size);
//Free the buffer.
LocalFree(messageBuffer);
return message;
}
// All processes in the group will shut down with the process creating the group
void* createProcessGroup() {
HANDLE jobObject = CreateJobObject(nullptr, nullptr);
if (jobObject == nullptr) {
qWarning() << "Could NOT create job object:" << getLastErrorAsString();
return nullptr;
}
JOBOBJECT_EXTENDED_LIMIT_INFORMATION JELI;
if (!QueryInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &JELI, sizeof(JELI), nullptr)) {
qWarning() << "Could NOT query job object information" << getLastErrorAsString();
return nullptr;
}
JELI.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
if (!SetInformationJobObject(jobObject, JobObjectExtendedLimitInformation, &JELI, sizeof(JELI))) {
qWarning() << "Could NOT set job object information" << getLastErrorAsString();
return nullptr;
}
return jobObject;
}
void addProcessToGroup(void* processGroup, qint64 processId) {
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processId);
if (hProcess == nullptr) {
qCritical() << "Could NOT open process" << getLastErrorAsString();
}
if (!AssignProcessToJobObject(processGroup, hProcess)) {
qCritical() << "Could NOT assign process to job object" << getLastErrorAsString();
}
}
#endif

View file

@ -238,4 +238,10 @@ void setMaxCores(uint8_t maxCores);
const QString PARENT_PID_OPTION = "parent-pid";
void watchParentProcess(int parentPID);
#ifdef Q_OS_WIN
void* createProcessGroup();
void addProcessToGroup(void* processGroup, qint64 processId);
#endif
#endif // hifi_SharedUtil_h