After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 729718 - Dramatically simplify alarm logic to stop timerfd leaks
Dramatically simplify alarm logic to stop timerfd leaks
Status: RESOLVED FIXED
Product: gnome-online-accounts
Classification: Core
Component: Kerberos
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2014-05-07 14:52 UTC by Ray Strode [halfline]
Modified: 2014-05-13 14:15 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
goaalarm: assume clear_scheduled_wakeups will only be called with a valid timer (4.13 KB, patch)
2014-05-07 14:52 UTC, Ray Strode [halfline]
committed Details | Review
Don't mangle state of attached timer when closing detached timer (3.54 KB, patch)
2014-05-07 14:52 UTC, Ray Strode [halfline]
needs-work Details | Review
goaalarm: nullify attached timer object when it gets closed (2.31 KB, patch)
2014-05-07 14:52 UTC, Ray Strode [halfline]
none Details | Review
goaalarm: assume clear_scheduled_wakeups will only be called with a valid timer (4.13 KB, patch)
2014-05-07 18:49 UTC, Ray Strode [halfline]
none Details | Review
goaalarm: don't mangle state of attached timer when closing detached timer (3.59 KB, patch)
2014-05-07 18:49 UTC, Ray Strode [halfline]
none Details | Review
goaalarm: nullify attached timer object when it gets closed (2.26 KB, patch)
2014-05-07 18:49 UTC, Ray Strode [halfline]
none Details | Review
goaalarm: create task while still hold lock (6.35 KB, patch)
2014-05-07 18:50 UTC, Ray Strode [halfline]
none Details | Review
goaalarm: don't dispatch handlers for stale timers (2.54 KB, patch)
2014-05-07 18:50 UTC, Ray Strode [halfline]
none Details | Review
identity: dramatically simplify alarm logic (36.68 KB, patch)
2014-05-08 18:18 UTC, Ray Strode [halfline]
none Details | Review
identity: dramatically simplify alarm logic (36.86 KB, patch)
2014-05-09 11:56 UTC, Ray Strode [halfline]
none Details | Review
identity: dramatically simplify alarm logic (36.87 KB, patch)
2014-05-09 12:14 UTC, Ray Strode [halfline]
committed Details | Review

Description Ray Strode [halfline] 2014-05-07 14:52:21 UTC
There is a still a timerfd leak going on.
Comment 1 Ray Strode [halfline] 2014-05-07 14:52:22 UTC
Created attachment 276071 [details] [review]
goaalarm: assume clear_scheduled_wakeups will only be called with a valid timer

Right now, clear_scheduled_wakeups will only clear the timer source
passed in, if there is a timer source scheduled.  But the timer
source passed in may have nothing to do with the currently scheduled
timer, so move that check to the caller of the function.
Comment 2 Ray Strode [halfline] 2014-05-07 14:52:25 UTC
Created attachment 276072 [details] [review]
Don't mangle state of attached timer when closing detached timer

Because we defer cleanup of timer sources until idle, we may have
one or more detached timers "in flight" waiting to be closed.

Right now, the function that closes the timers, also clears the
state about the currently attached timer, whic means when an
stale timer gets closed, we end up leaking the attached timer.

This commit changes the function that closes timers, to only
clear state about the currently attached timer, if the timer
being closed is the currently attached timer.
Comment 3 Ray Strode [halfline] 2014-05-07 14:52:28 UTC
Created attachment 276073 [details] [review]
goaalarm: nullify attached timer object when it gets closed

Right now, after closing a timer source, we leave it's pointer
dangling.  This commit fixes that.
Comment 4 Debarshi Ray 2014-05-07 15:25:14 UTC
Review of attachment 276071 [details] [review]:

Makes sense.
Comment 5 Ray Strode [halfline] 2014-05-07 18:47:32 UTC
Review of attachment 276072 [details] [review]:

::: src/goaidentity/goaalarm.c
@@ +91,3 @@
+
+  if (self->priv->scheduled_wakeup_source == source)
+    is_attached = TRUE;

this needs to set is_attached to FALSE in the else case
Comment 6 Ray Strode [halfline] 2014-05-07 18:49:41 UTC
Created attachment 276099 [details] [review]
goaalarm: assume clear_scheduled_wakeups will only be called with a valid timer

Right now, clear_scheduled_wakeups will only clear the timer source
passed in, if there is a timer source scheduled.  But the timer
source passed in may have nothing to do with the currently scheduled
timer, so move that check to the caller of the function.
Comment 7 Ray Strode [halfline] 2014-05-07 18:49:49 UTC
Created attachment 276100 [details] [review]
goaalarm: don't mangle state of attached timer when closing detached timer

Because we defer cleanup of timer sources until idle, we may have
one or more detached timers "in flight" waiting to be closed.

Right now, the function that closes the timers, also clears the
state about the currently attached timer, whic means when an
stale timer gets closed, we end up leaking the attached timer.

This commit changes the function that closes timers, to only
clear state about the currently attached timer, if the timer
being closed is the currently attached timer.
Comment 8 Ray Strode [halfline] 2014-05-07 18:49:58 UTC
Created attachment 276101 [details] [review]
goaalarm: nullify attached timer object when it gets closed

Right now, after closing a timer source, we leave it's pointer
dangling.  This commit fixes that.
Comment 9 Ray Strode [halfline] 2014-05-07 18:50:05 UTC
Created attachment 276102 [details] [review]
goaalarm: create task while still hold lock

The on_cancelled handler may be called outside of the
lock, if the cancellable is cancelled directly, rather
than via set_time.

Since it's not called under the lock, it's not "safe" to
examine the active timer source.

This commit moves construction of the task for the active
timer source to set_time, where it's safely under the lock.
Comment 10 Ray Strode [halfline] 2014-05-07 18:50:11 UTC
Created attachment 276103 [details] [review]
goaalarm: don't dispatch handlers for stale timers

If a handler is on life support just waiting to be destroyed,
we shouldn't keep using it.
Comment 11 Ray Strode [halfline] 2014-05-08 18:12:31 UTC
I think we need to rethink the approach here.  The code is way more complicated than it needs to be and these patches only make it more complicated.  Furthermore, I'm not convinced the problem is completely fixed, even with the patches.

Let me attach a different kind of fix that should mop this mess up in a better way.
Comment 12 Ray Strode [halfline] 2014-05-08 18:18:04 UTC
Created attachment 276187 [details] [review]
identity: dramatically simplify alarm logic

The GoaAlarm code is unwieldy. Primarily this is because
it supports resetting the alarm after creation, but can't
clean up old state right away due to a bug in GLib
(bug 705395). All this complexitly is leading to bugs, and
caos.

This commit introduces some zen to the situation by making
GoaAlarm immutable and much simpler. Now to reset an alarm,
the identity code just instantiates a new one and destroys the
old one.
Comment 13 Ray Strode [halfline] 2014-05-09 11:37:39 UTC
will post one more iteration to address a leak fix
Comment 14 Ray Strode [halfline] 2014-05-09 11:56:00 UTC
Created attachment 276237 [details] [review]
identity: dramatically simplify alarm logic

The GoaAlarm code is unwieldy. Primarily this is because
it supports resetting the alarm after creation, but can't
clean up old state right away due to a bug in GLib
(bug 705395). All this complexitly is leading to bugs, and
caos.

This commit introduces some zen to the situation by making
GoaAlarm immutable and much simpler. Now to reset an alarm,
the identity code just instantiates a new one and destroys the
old one.
Comment 15 Ray Strode [halfline] 2014-05-09 12:07:26 UTC
and one more iteration to make it apply now that bug 729864 has landed
Comment 16 Ray Strode [halfline] 2014-05-09 12:14:22 UTC
Created attachment 276240 [details] [review]
identity: dramatically simplify alarm logic

The GoaAlarm code is unwieldy. Primarily this is because
it supports resetting the alarm after creation, but can't
clean up old state right away due to a bug in GLib
(bug 705395). All this complexitly is leading to bugs, and
caos.

This commit introduces some zen to the situation by making
GoaAlarm immutable and much simpler. Now to reset an alarm,
the identity code just instantiates a new one and destroys the
old one.
Comment 17 Debarshi Ray 2014-05-12 15:46:56 UTC
Review of attachment 276240 [details] [review]:

Yes, looks good. Thanks for the patch, Ray!
Comment 18 Ray Strode [halfline] 2014-05-12 17:52:47 UTC
Attachment 276240 [details] pushed as b2f1b8a - identity: dramatically simplify alarm logic