Skip to content

Commit

Permalink
Wait for housekeeping to finish before bbstored exits
Browse files Browse the repository at this point in the history
Should fix random test failures due to housekeeping process realising that the
master has asked it to terminate, and logging that it has, after the master has
already died and the test finished, confusing the test runner with its extra
output. Should also help make the occasionally-reported housekeeping crashes
more obvious and easier to debug.
  • Loading branch information
qris committed Oct 7, 2017
1 parent 32a4c7b commit f748339
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/bbstored/BBStoreDHousekeeping.cpp
Expand Up @@ -217,6 +217,7 @@ bool BackupStoreDaemon::CheckForInterProcessMsg(int AccountNum, int MaximumWaitT
// First, check to see if it's EOF -- this means something has gone wrong, and the housekeeping should terminate.
if(mInterProcessComms.IsEOF())
{
BOX_INFO("Housekeeping process was hungup by main daemon, terminating");
SetTerminateWanted();
return true;
}
Expand Down
37 changes: 36 additions & 1 deletion lib/bbstored/BackupStoreDaemon.cpp
Expand Up @@ -171,6 +171,7 @@ void BackupStoreDaemon::Run()
mExtendedLogging = false;
const Configuration &config(GetConfiguration());
mExtendedLogging = config.GetKeyValueBool("ExtendedLogging");
int housekeeping_pid;

// Fork off housekeeping daemon -- must only do this the first
// time Run() is called. Housekeeping runs synchronously on Win32
Expand All @@ -188,7 +189,8 @@ void BackupStoreDaemon::Run()
int whichSocket = 0;

// Fork
switch(::fork())
housekeeping_pid = ::fork();
switch(housekeeping_pid)
{
case -1:
{
Expand Down Expand Up @@ -259,6 +261,39 @@ void BackupStoreDaemon::Run()
if(IsTerminateWanted())
{
mInterProcessCommsSocket.Write("t\n", 2);

#ifndef WIN32 // waitpid() only works with fork(), and thus not on Windows
// Wait for housekeeping to finish, and report its status, otherwise it
// can remain running and write to the console after the main process has
// died, which can confuse the tests.
int child_state;
if(waitpid(housekeeping_pid, &child_state, 0) == -1)
{
BOX_LOG_SYS_ERROR("Failed to wait for housekeeping child process "
"to finish");
}
else if(WIFEXITED(child_state))
{
if(WEXITSTATUS(child_state) == 0)
{
BOX_TRACE("Housekeeping child process exited normally");
}
else
{
BOX_ERROR("Housekeeping child process exited with "
"status " << WEXITSTATUS(child_state));
}
}
else if(WIFSIGNALED(child_state))
{
BOX_ERROR("Housekeeping child process terminated with signal " <<
WTERMSIG(child_state));
}
else
{
BOX_ERROR("Housekeeping child process terminated in unexpected manner");
}
#endif // !WIN32
}
}
}
Expand Down

0 comments on commit f748339

Please sign in to comment.