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 711696 - Leaking timerfds when we fall back to polling the ccache
Leaking timerfds when we fall back to polling the ccache
Status: RESOLVED FIXED
Product: gnome-online-accounts
Classification: Core
Component: Kerberos
3.10.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME Online Accounts maintainer(s)
GNOME Online Accounts maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2013-11-08 16:14 UTC by Debarshi Ray
Modified: 2013-11-12 16:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
alarm: Do not clear the wrong objects when setting the time (2.89 KB, patch)
2013-11-08 17:48 UTC, Debarshi Ray
committed Details | Review
alarm: The global default main context is always the same (969 bytes, patch)
2013-11-08 17:49 UTC, Debarshi Ray
reviewed Details | Review
alarm: Use the same GSource pointer for TIMER and TIMEOUT alarms (4.90 KB, patch)
2013-11-11 13:43 UTC, Debarshi Ray
reviewed Details | Review
alarm: Tag the "cancelled" handler with the correct source and stream (5.41 KB, patch)
2013-11-11 13:43 UTC, Debarshi Ray
reviewed Details | Review
alarm: Remove redundant preprocessor conditional (1.15 KB, patch)
2013-11-11 13:49 UTC, Debarshi Ray
committed Details | Review
alarm: The global default main context is always the same (969 bytes, patch)
2013-11-11 19:47 UTC, Debarshi Ray
committed Details | Review
alarm: Use the same GSource pointer for TIMER and TIMEOUT alarms (4.93 KB, patch)
2013-11-11 19:48 UTC, Debarshi Ray
committed Details | Review
alarm: Tag the "cancelled" handler with the correct source and stream (5.49 KB, patch)
2013-11-11 19:50 UTC, Debarshi Ray
accepted-commit_now Details | Review
alarm: Consolidate clear_scheduled_time*_wakeups into one function (2.34 KB, patch)
2013-11-12 10:02 UTC, Debarshi Ray
committed Details | Review
alarm: Tag the "cancelled" handler with the correct source and stream (5.48 KB, patch)
2013-11-12 15:30 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2013-11-08 16:14:08 UTC
Looks similar to bug 691142 on the outside, but I think this only manifests itself when we poll the credentials cache because we can not monitor it.

When we poll we keep pushing the renewal_time forward [1] which causes renewal_alarm to be reset. That leads us to goa_alarm_set_time [2] where we cancel the old self->priv->cancellable and replace it with a new one. This leads to clear_scheduled_wakeups being run in a idle callback, however before that can run we call schedule_wakeups. This causes the timer.stream to be leaked.

I am suspicious of clear_scheduled_wakeups because it again clears self->priv->cancellable and self->priv->context, which in this case are the new ones set by goa_alarm_set_time. Maybe we should move them to dispose?

Looks like we tackled a similar problem in bug 708975 Similar to what we did there we need to somehow tag the old stream and source that need to be cleaned in on_cancelled.

[1] https://git.gnome.org/browse/gnome-online-accounts/tree/src/goaidentity/goakerberosidentity.c#n867
[2] https://git.gnome.org/browse/gnome-online-accounts/tree/src/goaidentity/goaalarm.c#n606
[3] https://git.gnome.org/browse/gnome-online-accounts/tree/src/goaidentity/goaalarm.c#n134
Comment 1 Debarshi Ray 2013-11-08 17:48:59 UTC
Created attachment 259293 [details] [review]
alarm: Do not clear the wrong objects when setting the time
Comment 2 Debarshi Ray 2013-11-08 17:49:30 UTC
Created attachment 259294 [details] [review]
alarm: The global default main context is always the same
Comment 3 Debarshi Ray 2013-11-11 13:43:12 UTC
Created attachment 259560 [details] [review]
alarm: Use the same GSource pointer for TIMER and TIMEOUT alarms
Comment 4 Debarshi Ray 2013-11-11 13:43:45 UTC
Created attachment 259561 [details] [review]
alarm: Tag the "cancelled" handler with the correct source and stream
Comment 5 Debarshi Ray 2013-11-11 13:49:49 UTC
Created attachment 259562 [details] [review]
alarm: Remove redundant preprocessor conditional
Comment 6 Ray Strode [halfline] 2013-11-11 15:50:53 UTC
Review of attachment 259562 [details] [review]:

++
Comment 7 Ray Strode [halfline] 2013-11-11 18:25:06 UTC
Review of attachment 259293 [details] [review]:

so this should be squashed with the next attachment right?
Comment 8 Ray Strode [halfline] 2013-11-11 18:25:41 UTC
Review of attachment 259294 [details] [review]:

::: src/goaidentity/goaalarm.c
@@ +645,3 @@
   self->priv->time = time;
 
+  if (self->priv->context != NULL)

shouldn't that be == NULL?
Comment 9 Ray Strode [halfline] 2013-11-11 18:31:39 UTC
Review of attachment 259560 [details] [review]:

::: src/goaidentity/goaalarm.c
@@ +61,3 @@
   GoaAlarmType type;
+  GSource *scheduled_wakeup_source;
+  GInputStream *stream;

should have a comment above this that says somethine like /* NULL unless using timerfd() */

@@ +97,3 @@
   gboolean is_closed;
 
+  g_clear_pointer (&self->priv->scheduled_wakeup_source, (GDestroyNotify) g_source_destroy);

Since we're using the same source variable now for both timer/timeout codepaths it may make sense to consolidate clear_scheduled_time*_wakeups into one function.
Comment 10 Ray Strode [halfline] 2013-11-11 18:34:34 UTC
Review of attachment 259561 [details] [review]:

::: src/goaidentity/goaalarm.c
@@ +258,3 @@
+  self = g_task_get_source_object (task);
+  source = (GSource *) g_object_get_data (G_OBJECT (task), "alarm-scheduled-wakeup-source");
+  stream = G_INPUT_STREAM (g_object_get_data (G_OBJECT (task), "alarm-stream"));

This is going to spew to the console if timerfd isn't compiled in right? (since alarm-stream will be NULL)
Comment 11 Debarshi Ray 2013-11-11 19:03:58 UTC
(In reply to comment #7)
> Review of attachment 259293 [details] [review]:
> 
> so this should be squashed with the next attachment right?

Yes. I kept them separate for the purposes of the review.
Comment 12 Debarshi Ray 2013-11-11 19:04:20 UTC
(In reply to comment #8)
> Review of attachment 259294 [details] [review]:
> 
> ::: src/goaidentity/goaalarm.c
> @@ +645,3 @@
>    self->priv->time = time;
> 
> +  if (self->priv->context != NULL)
> 
> shouldn't that be == NULL?

Yes, ofcourse.
Comment 13 Debarshi Ray 2013-11-11 19:11:05 UTC
(In reply to comment #10)
> Review of attachment 259561 [details] [review]:
> 
> ::: src/goaidentity/goaalarm.c
> @@ +258,3 @@
> +  self = g_task_get_source_object (task);
> +  source = (GSource *) g_object_get_data (G_OBJECT (task),
> "alarm-scheduled-wakeup-source");
> +  stream = G_INPUT_STREAM (g_object_get_data (G_OBJECT (task),
> "alarm-stream"));
> 
> This is going to spew to the console if timerfd isn't compiled in right? (since
> alarm-stream will be NULL)

Yes, you are right.
Comment 14 Debarshi Ray 2013-11-11 19:47:56 UTC
Created attachment 259586 [details] [review]
alarm: The global default main context is always the same
Comment 15 Debarshi Ray 2013-11-11 19:48:53 UTC
Created attachment 259587 [details] [review]
alarm: Use the same GSource pointer for TIMER and TIMEOUT alarms
Comment 16 Debarshi Ray 2013-11-11 19:50:06 UTC
Created attachment 259588 [details] [review]
alarm: Tag the "cancelled" handler with the correct source and stream
Comment 17 Debarshi Ray 2013-11-11 19:54:00 UTC
(In reply to comment #9)
> @@ +97,3 @@
>    gboolean is_closed;
> 
> +  g_clear_pointer (&self->priv->scheduled_wakeup_source, (GDestroyNotify)
> g_source_destroy);
> 
> Since we're using the same source variable now for both timer/timeout codepaths
> it may make sense to consolidate clear_scheduled_time*_wakeups into one
> function.

Yes. My quick attempt at this is spewing some CRITICALs to the terminal, and I got to run now. Will attach something tomorrow morning.
Comment 18 Debarshi Ray 2013-11-12 10:02:03 UTC
Created attachment 259645 [details] [review]
alarm: Consolidate clear_scheduled_time*_wakeups into one function
Comment 19 Ray Strode [halfline] 2013-11-12 12:57:11 UTC
Review of attachment 259588 [details] [review]:

This seems okay (modulo minor buglet mentioned below).  Now that we can have overlapping streams/sources I wonder if the stream, source, and cancellable should be moved out of the main GoaAlarmPrivate and be stored entirely in task specific data, but that's maybe a cleanup for another day.

::: src/goaidentity/goaalarm.c
@@ +255,3 @@
+  GSource *source;
+  GTask *task = G_TASK (user_data);
+  gpointer *task_data;

gpointer not gpointer *

@@ +260,3 @@
+  source = (GSource *) g_object_get_data (G_OBJECT (task), "alarm-scheduled-wakeup-source");
+  task_data = g_object_get_data (G_OBJECT (task), "alarm-stream");
+  stream = (task_data == NULL) ? NULL : G_INPUT_STREAM (task_data);

this is fine, but i think it would be a little cleaner to pass the type in as object data as well and then only set stream if the type is the kind that has a stream. That would allow you to keep the G_INPUT_STREAM runtime check for the timerfd code-path in case things go wonky and the stream somehow gets nullified.  Anyway it doesn't really matter either way.
Comment 20 Ray Strode [halfline] 2013-11-12 12:57:59 UTC
Review of attachment 259645 [details] [review]:

++
Comment 21 Debarshi Ray 2013-11-12 15:28:22 UTC
(In reply to comment #19)
> Review of attachment 259588 [details] [review]:
> 
> This seems okay (modulo minor buglet mentioned below).  Now that we can have
> overlapping streams/sources I wonder if the stream, source, and cancellable
> should be moved out of the main GoaAlarmPrivate and be stored entirely in task
> specific data, but that's maybe a cleanup for another day.
> 
> ::: src/goaidentity/goaalarm.c
> @@ +255,3 @@
> +  GSource *source;
> +  GTask *task = G_TASK (user_data);
> +  gpointer *task_data;
> 
> gpointer not gpointer *

Oops! Fixed.

> @@ +260,3 @@
> +  source = (GSource *) g_object_get_data (G_OBJECT (task),
> "alarm-scheduled-wakeup-source");
> +  task_data = g_object_get_data (G_OBJECT (task), "alarm-stream");
> +  stream = (task_data == NULL) ? NULL : G_INPUT_STREAM (task_data);
> 
> this is fine, but i think it would be a little cleaner to pass the type in as
> object data as well and then only set stream if the type is the kind that has a
> stream. That would allow you to keep the G_INPUT_STREAM runtime check for the
> timerfd code-path in case things go wonky and the stream somehow gets
> nullified.  Anyway it doesn't really matter either way.

I decided not to use the GoaAlarmType because now that we are using the same GSource * for both TIMER and TIMEOUT alarms, we might be able to get away with the type being a binary (scheduled / unscheduled) instead of a tri-state.
Comment 22 Debarshi Ray 2013-11-12 15:30:07 UTC
Created attachment 259670 [details] [review]
alarm: Tag the "cancelled" handler with the correct source and stream
Comment 23 Debarshi Ray 2013-11-12 16:04:21 UTC
Committed to both master and gnome-3-10. Will backport to gnome-3-8 after some more testing.