Skip to content

Commit

Permalink
Message indexer was not cleanly shut down.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinknafve committed Sep 25, 2014
1 parent de3cb36 commit 96a4840
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 2 additions & 0 deletions hmailserver/source/Server/Common/Application/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ namespace HM
if (notification_server_) notification_server_.reset();
if (folder_manager_) folder_manager_.reset();

MessageIndexer::Instance()->Stop();

ServerStatus::Instance()->SetState(ServerStatus::StateStopped);

LOG_APPLICATION("Servers stopped.")
Expand Down
19 changes: 13 additions & 6 deletions hmailserver/source/Server/Common/Application/MessageIndexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace HM
}
}
// Start the indexer now.
LOG_DEBUG("Starting message indexing thread...");
LOG_DEBUG("Starting message indexer...");

boost::function<void ()> func = boost::bind( &MessageIndexer::WorkerFunc, this );
workerThread_ = boost::thread(func);
Expand All @@ -55,14 +55,14 @@ namespace HM
MessageIndexer::WorkerFunc()
{
boost::function<void()> func = boost::bind( &MessageIndexer::WorkerFuncInternal, this );
if (ExceptionHandler::Run("MessageIndexer", func))
return;
ExceptionHandler::Run("MessageIndexer", func);
LOG_DEBUG("Message indexer stopped.");
}

void
MessageIndexer::WorkerFuncInternal()
{
LOG_DEBUG("Indexing messages...");
LOG_DEBUG("Message indexer started...");

PersistentMessageMetaData persistentMetaData;
persistentMetaData.DeleteOrphanedItems();
Expand All @@ -86,10 +86,17 @@ namespace HM
void
MessageIndexer::Stop()
{
workerThread_.interrupt();
if (workerThread_.joinable())
{
if (!workerThread_.timed_join(boost::posix_time::milliseconds(1)))
{
// thread is running. interrupt it.
LOG_DEBUG("Stopping message indexer.");
workerThread_.interrupt();
}
}
}


void
MessageIndexer::IndexMessages_()
{
Expand Down

0 comments on commit 96a4840

Please sign in to comment.