]> granicus.if.org Git - icinga2/commitdiff
Bugfix: Unhandled exception in Service::CheckTimerHandler.
authorGunnar Beutner <gunnar.beutner@netways.de>
Fri, 1 Feb 2013 18:27:36 +0000 (19:27 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Fri, 1 Feb 2013 18:27:36 +0000 (19:27 +0100)
Fixes #3607

components/checker/checkercomponent.cpp
lib/icinga/service.cpp

index e3ab57e7bb2e1a2bc4fa45330d8bae8d02820ca0..be154436d01818e2d81d10fa243a3097f4a0f6d3 100644 (file)
@@ -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++;
        }
index 265879c441be78ff0be72254ae66ca75dd436132..c1184f1f6009fb311c14c0edd53fc91cce731c84 100644 (file)
@@ -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,