fix: Improve Windows daemon stop speed by using non-blocking pipes and shorter sleep times
This commit is contained in:
parent
890fd61e6e
commit
19c41e2ac5
2 changed files with 16 additions and 10 deletions
|
|
@ -9,9 +9,7 @@
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
#include "arch/win32/ArchMiscWindows.h"
|
#include "arch/win32/ArchMiscWindows.h"
|
||||||
#include "arch/win32/XArchWindows.h"
|
#include "arch/win32/XArchWindows.h"
|
||||||
#include "common/stdvector.h"
|
#include "base/Log.h"
|
||||||
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// ArchDaemonWindows
|
// ArchDaemonWindows
|
||||||
|
|
@ -165,9 +163,10 @@ void ArchDaemonWindows::uninstallDaemon(const char *name)
|
||||||
CloseServiceHandle(service);
|
CloseServiceHandle(service);
|
||||||
CloseServiceHandle(mgr);
|
CloseServiceHandle(mgr);
|
||||||
|
|
||||||
// give windows a chance to remove the service before
|
// give windows a chance to remove the service before we check if it still exists.
|
||||||
// we check if it still exists.
|
// 100ms should be plenty of time.
|
||||||
ARCH->sleep(1);
|
LOG_DEBUG("waiting for service to be removed");
|
||||||
|
ARCH->sleep(0.1);
|
||||||
|
|
||||||
// handle failure. ignore error if service isn't installed anymore.
|
// handle failure. ignore error if service isn't installed anymore.
|
||||||
if (!okay && isDaemonInstalled(name)) {
|
if (!okay && isDaemonInstalled(name)) {
|
||||||
|
|
|
||||||
|
|
@ -188,6 +188,13 @@ void MSWindowsWatchdog::mainLoop(void *)
|
||||||
throw XArch(new XArchEvalWindows());
|
throw XArch(new XArchEvalWindows());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the pipe to non-blocking mode, which allows us to stop the output reader thread immediately
|
||||||
|
// in order to speed up the shutdown process when the Windows service needs to stop.
|
||||||
|
DWORD mode = PIPE_NOWAIT;
|
||||||
|
if (!SetNamedPipeHandleState(m_outputReadPipe, &mode, nullptr, nullptr)) {
|
||||||
|
throw XArch(new XArchEvalWindows());
|
||||||
|
}
|
||||||
|
|
||||||
while (m_monitoring) {
|
while (m_monitoring) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
@ -247,7 +254,8 @@ void MSWindowsWatchdog::mainLoop(void *)
|
||||||
LOG((CLOG_ERR "could not create SendSAS event"));
|
LOG((CLOG_ERR "could not create SendSAS event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
ARCH->sleep(1);
|
// Sleep for only 100ms rather than 1 second so that the service can shut down faster.
|
||||||
|
ARCH->sleep(0.1);
|
||||||
|
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
LOG((CLOG_CRIT "failed to launch, error: %s", e.what()));
|
LOG((CLOG_CRIT "failed to launch, error: %s", e.what()));
|
||||||
|
|
@ -401,10 +409,9 @@ void MSWindowsWatchdog::outputLoop(void *)
|
||||||
DWORD bytesRead;
|
DWORD bytesRead;
|
||||||
BOOL success = ReadFile(m_outputReadPipe, buffer, kOutputBufferSize, &bytesRead, NULL);
|
BOOL success = ReadFile(m_outputReadPipe, buffer, kOutputBufferSize, &bytesRead, NULL);
|
||||||
|
|
||||||
// assume the process has gone away? slow down
|
|
||||||
// the reads until another one turns up.
|
|
||||||
if (!success || bytesRead == 0) {
|
if (!success || bytesRead == 0) {
|
||||||
ARCH->sleep(1);
|
// Sleep for only 100ms rather than 1 second so that the service can shut down faster.
|
||||||
|
ARCH->sleep(0.1);
|
||||||
} else {
|
} else {
|
||||||
buffer[bytesRead] = '\0';
|
buffer[bytesRead] = '\0';
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue