Skip to content

Fix crash when notifications are sent while the notification object is deleted #8591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2021

Conversation

julianbrost
Copy link
Contributor

When sending notifications, an asynchronous callback is scheduled which captures the this pointer which is not reference-counted. This PR fixes this by using a reference-counted Notification::Ptr instead.

fixes #8587

@icinga-probot icinga-probot bot added area/distributed Distributed monitoring (master, satellites, clients) area/notifications Notification events core/crash Shouldn't happen, requires attention labels Jan 11, 2021
@icinga-probot icinga-probot bot added this to the 2.13.0 milestone Jan 11, 2021
@julianbrost julianbrost requested a review from Al2Klimov January 11, 2021 17:18
`this` could be deleted after `Notification::BeginExecuteNotification`
exited and before `Notification::ExecuteNotificationHelper` finished.
This is fixed by constructing a `Notification::Ptr` and operate on that
one as it is properly reference-counted.
@julianbrost julianbrost force-pushed the bugfix/concurent-notification-send-and-delete branch from 1b4918a to aea06a2 Compare January 12, 2021 16:19
@@ -431,7 +431,11 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
<< "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToString(type) << "' notification '"
<< notificationName << "' for user '" << userName << "'";

Utility::QueueAsyncCallback(std::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
// Explicitly use Notification::Ptr to keep the reference counted while the callback is active
Notification::Ptr notification (this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pro tip: Due to the context you could also just use Ptr as type. But I don’t demand that.

@Al2Klimov Al2Klimov merged commit f1110eb into master Jan 13, 2021
@icinga-probot icinga-probot bot deleted the bugfix/concurent-notification-send-and-delete branch January 13, 2021 09:58
@julianbrost julianbrost added the consider backporting Should be considered for inclusion in a bugfix release label Apr 12, 2021
@N-o-X N-o-X added backported Fix was included in a bugfix release and removed consider backporting Should be considered for inclusion in a bugfix release labels Jul 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/distributed Distributed monitoring (master, satellites, clients) area/notifications Notification events backported Fix was included in a bugfix release core/crash Shouldn't happen, requires attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Icinga has terminated unexpectatedly after API interaction
3 participants