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.

(cherry picked from commit 0100d31)
  • Loading branch information
qris committed Jan 15, 2018
1 parent aaa5301 commit 2cc729b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/bbstored/BBStoreDHousekeeping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ bool BackupStoreDaemon::CheckForInterProcessMsg(int AccountNum, int MaximumWaitT
return false;
}

// 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;
}

// Get a line, and process the message
std::string line;

Expand Down
37 changes: 36 additions & 1 deletion lib/bbstored/BackupStoreDaemon.cpp
Original file line number Diff line number Diff line change
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 @@ -190,7 +191,8 @@ void BackupStoreDaemon::Run()
int whichSocket = 0;

// Fork
switch(::fork())
housekeeping_pid = ::fork();
switch(housekeeping_pid)
{
case -1:
{
Expand Down Expand Up @@ -261,6 +263,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 2cc729b

Please sign in to comment.