Skip to content

Commit 911238f

Browse files
committed
Keep object locked until events are dispatched.
1 parent 206d7cd commit 911238f

File tree

1 file changed

+42
-53
lines changed

1 file changed

+42
-53
lines changed

lib/icinga/checkable-check.cpp

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
9898
{
9999
using Result = Checkable::ProcessingResult;
100100

101-
{
102-
ObjectLock olock(this);
103-
m_CheckRunning = false;
104-
}
101+
ObjectLock olock(this);
102+
m_CheckRunning = false;
105103

106104
if (!cr)
107105
return Result::NoCheckResult;
@@ -154,8 +152,6 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
154152
bool reachable = IsReachable();
155153
bool notification_reachable = IsReachable(DependencyNotification);
156154

157-
ObjectLock olock(this);
158-
159155
CheckResult::Ptr old_cr = GetLastCheckResult();
160156
ServiceState old_state = GetStateRaw();
161157
StateType old_stateType = GetStateType();
@@ -318,8 +314,6 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
318314
if (is_volatile && IsStateOK(old_state) && IsStateOK(new_state))
319315
send_notification = false; /* Don't send notifications for volatile OK -> OK changes. */
320316

321-
olock.Unlock();
322-
323317
if (remove_acknowledgement_comments)
324318
RemoveAckComments(String(), cr->GetExecutionEnd());
325319

@@ -335,25 +329,14 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
335329

336330
cr->SetVarsAfter(vars_after);
337331

338-
olock.Lock();
339-
332+
bool problem_change = false;
340333
if (service) {
341334
SetLastCheckResult(cr);
342335
} else {
343336
bool wasProblem = GetProblem();
344-
345337
SetLastCheckResult(cr);
346-
347-
if (GetProblem() != wasProblem) {
348-
auto services = host->GetServices();
349-
olock.Unlock();
350-
for (auto& service : services) {
351-
Service::OnHostProblemChanged(service, cr, origin);
352-
}
353-
olock.Lock();
354-
}
338+
problem_change = GetProblem() != wasProblem;
355339
}
356-
357340
bool was_flapping = IsFlapping();
358341

359342
UpdateFlappingStatus(cr->GetState());
@@ -384,8 +367,6 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
384367
}
385368
}
386369

387-
olock.Unlock();
388-
389370
#ifdef I2_DEBUG /* I2_DEBUG */
390371
Log(LogDebug, "Checkable")
391372
<< "Flapping: Checkable " << GetName()
@@ -396,35 +377,6 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
396377
<< "% current: " << GetFlappingCurrent() << "%.";
397378
#endif /* I2_DEBUG */
398379

399-
if (recovery) {
400-
for (auto& child : children) {
401-
if (child->GetProblem() && child->GetEnableActiveChecks()) {
402-
auto nextCheck (now + Utility::Random() % 60);
403-
404-
ObjectLock oLock (child);
405-
406-
if (nextCheck < child->GetNextCheck()) {
407-
child->SetNextCheck(nextCheck);
408-
}
409-
}
410-
}
411-
}
412-
413-
if (stateChange) {
414-
/* reschedule direct parents */
415-
for (const Checkable::Ptr& parent : GetParents()) {
416-
if (parent.get() == this)
417-
continue;
418-
419-
if (!parent->GetEnableActiveChecks())
420-
continue;
421-
422-
if (parent->GetNextCheck() >= now + parent->GetRetryInterval()) {
423-
ObjectLock olock(parent);
424-
parent->SetNextCheck(now);
425-
}
426-
}
427-
}
428380

429381
OnNewCheckResult(this, cr, origin);
430382

@@ -506,7 +458,6 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
506458
* stash them into a notification types bitmask for maybe re-sending later.
507459
*/
508460

509-
ObjectLock olock (this);
510461
int suppressed_types_before (GetSuppressedNotifications());
511462
int suppressed_types_after (suppressed_types_before | suppressed_types);
512463

@@ -536,6 +487,44 @@ Checkable::ProcessingResult Checkable::ProcessCheckResult(const CheckResult::Ptr
536487
if ((stateChange || hardChange) && !children.empty())
537488
OnReachabilityChanged(this, cr, children, origin);
538489

490+
olock->Unlock();
491+
if (!service && problem_change) {
492+
auto services = host->GetServices();
493+
for (auto& service : services) {
494+
Service::OnHostProblemChanged(service, cr, origin);
495+
}
496+
}
497+
498+
if (recovery) {
499+
for (auto& child : children) {
500+
if (child->GetProblem() && child->GetEnableActiveChecks()) {
501+
auto nextCheck (now + Utility::Random() % 60);
502+
503+
ObjectLock oLock (child);
504+
505+
if (nextCheck < child->GetNextCheck()) {
506+
child->SetNextCheck(nextCheck);
507+
}
508+
}
509+
}
510+
}
511+
512+
if (stateChange) {
513+
/* reschedule direct parents */
514+
for (const Checkable::Ptr& parent : GetParents()) {
515+
if (parent.get() == this)
516+
continue;
517+
518+
if (!parent->GetEnableActiveChecks())
519+
continue;
520+
521+
if (parent->GetNextCheck() >= now + parent->GetRetryInterval()) {
522+
ObjectLock olock(parent);
523+
parent->SetNextCheck(now);
524+
}
525+
}
526+
}
527+
539528
return Result::Ok;
540529
}
541530

0 commit comments

Comments
 (0)