[icinga-checkins] icinga.org: icinga2/master: Bugfix: Unhandled exception in Service:: CheckTimerHandler.

git at icinga.org git at icinga.org
Fri Feb 1 19:27:42 CET 2013


Module: icinga2
Branch: master
Commit: 5492d6fac38a66172205711a9e96141c6b0b6a61
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=5492d6fac38a66172205711a9e96141c6b0b6a61

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Fri Feb  1 19:27:36 2013 +0100

Bugfix: Unhandled exception in Service::CheckTimerHandler.

Fixes #3607

---

 components/checker/checkercomponent.cpp |    6 +++++-
 lib/icinga/service.cpp                  |   21 +++++++++++++++------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp
index e3ab57e..be15443 100644
--- a/components/checker/checkercomponent.cpp
+++ b/components/checker/checkercomponent.cpp
@@ -105,7 +105,11 @@ void CheckerComponent::CheckTimerHandler(void)
 		m_IdleServices.erase(service);
 		m_PendingServices.insert(service);
 
-		service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, this, service));
+		try {
+			service->BeginExecuteCheck(boost::bind(&CheckerComponent::CheckCompletedHandler, this, service));
+		} catch (const exception& ex) {
+			Logger::Write(LogCritical, "checker", "Exception occured while checking service '" + service->GetName() + "': " + ex.what());
+		}
 
 		tasks++;
 	}
diff --git a/lib/icinga/service.cpp b/lib/icinga/service.cpp
index 265879c..c1184f1 100644
--- a/lib/icinga/service.cpp
+++ b/lib/icinga/service.cpp
@@ -682,13 +682,22 @@ void Service::BeginExecuteCheck(const function<void (void)>& callback)
 	scheduleInfo->Set("schedule_start", GetNextCheck());
 	scheduleInfo->Set("execution_start", Utility::GetTime());
 
-	vector<Value> arguments;
-	arguments.push_back(static_cast<Service::Ptr>(GetSelf()));
-	ScriptTask::Ptr task;
-	task = InvokeMethod("check", arguments, boost::bind(&Service::CheckCompletedHandler, this, scheduleInfo, _1, callback));
-	assert(task); /* TODO: gracefully handle missing methods */
+	try {
+		vector<Value> arguments;
+		arguments.push_back(static_cast<Service::Ptr>(GetSelf()));
+		ScriptTask::Ptr task;
+		task = InvokeMethod("check", arguments, boost::bind(&Service::CheckCompletedHandler, this, scheduleInfo, _1, callback));
+		Set("current_task", task);
+	} catch (...) {
+		/* something went wrong while setting up the method call -
+		 * reschedule the service and call the callback anyway. */
+
+		UpdateNextCheck();
 
-	Set("current_task", task);
+		callback();
+
+		throw;
+	}
 }
 
 void Service::CheckCompletedHandler(const Dictionary::Ptr& scheduleInfo,





More information about the icinga-checkins mailing list