From b397d727dcaa3c9a12841acd488b18efb7d0c9ea Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 8 Aug 2012 11:02:39 +0200 Subject: [PATCH] b/f: db_reg_agent: also shutdown cleanly on rapid shutdown (e.g. signal 15) otherwise the processing thread continues to run, and the process crashes on shutdown --- apps/db_reg_agent/DBRegAgent.cpp | 15 +++++++++++++++ apps/db_reg_agent/DBRegAgent.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/apps/db_reg_agent/DBRegAgent.cpp b/apps/db_reg_agent/DBRegAgent.cpp index 7aada697..6e4b8aca 100644 --- a/apps/db_reg_agent/DBRegAgent.cpp +++ b/apps/db_reg_agent/DBRegAgent.cpp @@ -240,6 +240,19 @@ int DBRegAgent::onLoad() } void DBRegAgent::onUnload() { + if (running) { + running = false; + DBG("unclean shutdown. Waiting for processing thread to stop.\n"); + for (int i=0;i<20;i++) { + if (shutdown_finished) + break; + usleep(2000); // 2ms + } + if (!shutdown_finished) { + WARN("processing thread could not be stopped, process will probably crash\n"); + } + } + DBG("closing main DB connection\n"); MainDBConnection.disconnect(); DBG("closing auxiliary DB connection\n"); @@ -878,6 +891,7 @@ void DBRegAgent::run() { registration_processor.start(); } + shutdown_finished = false; DBG("running DBRegAgent thread...\n"); while (running) { processEvents(); @@ -899,6 +913,7 @@ void DBRegAgent::run() { mysqlpp::Connection::thread_end(); DBG("DBRegAgent thread stopped.\n"); + shutdown_finished = true; } void DBRegAgent::on_stop() { diff --git a/apps/db_reg_agent/DBRegAgent.h b/apps/db_reg_agent/DBRegAgent.h index 9ea3903b..bbb0861e 100644 --- a/apps/db_reg_agent/DBRegAgent.h +++ b/apps/db_reg_agent/DBRegAgent.h @@ -230,8 +230,12 @@ class DBRegAgent unsigned int expires; + /** processing thread running? */ bool running; + /** processing thread shutdown finished? */ + bool shutdown_finished; + AmDynInvoke* uac_auth_i; void DIcreateRegistration(int subscriber_id, const string& user,