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 710724 - gmain: Warn when g_source_remove() fails
gmain: Warn when g_source_remove() fails
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2013-10-23 13:41 UTC by Bastien Nocera
Modified: 2013-10-28 18:10 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gmain: Warn when g_source_remove() fails (1.36 KB, patch)
2013-10-23 13:41 UTC, Bastien Nocera
reviewed Details | Review
gmain: Warn when g_source_remove() fails (1.36 KB, patch)
2013-10-23 14:55 UTC, Bastien Nocera
none Details | Review
gmain: Warn when g_source_remove() fails (2.32 KB, patch)
2013-10-23 15:13 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gmain: test g_source_remove() with invalid ID (1.29 KB, patch)
2013-10-23 15:14 UTC, Allison Karlitskaya (desrt)
committed Details | Review
tests: expect critical on failure to remove source (1.28 KB, patch)
2013-10-23 15:14 UTC, Allison Karlitskaya (desrt)
committed Details | Review
gtester: only remove source if not already dead (862 bytes, patch)
2013-10-23 18:18 UTC, Allison Karlitskaya (desrt)
committed Details | Review

Description Bastien Nocera 2013-10-23 13:41:03 UTC
.
Comment 1 Bastien Nocera 2013-10-23 13:41:11 UTC
Created attachment 257920 [details] [review]
gmain: Warn when g_source_remove() fails

Trying to remove a non-existent source should really be
a programming error, as the programmer could be trying to
use the wrong function to remove a callback, as seen when
GtkScrolledWindow tried to remove ID from another function
using g_source_remove().

See: https://bugzilla.gnome.org/show_bug.cgi?id=710666#c12
Comment 2 Allison Karlitskaya (desrt) 2013-10-23 14:32:52 UTC
Review of attachment 257920 [details] [review]:

::: glib/gmain.c
@@ +2182,3 @@
     g_source_destroy (source);
+  else
+    g_warning ("Source ID %i was not found when attempting to remove it", tag);

g_critical() for programmer error please.

also: I think you want %u here because tags are unsigned ints.
Comment 3 Bastien Nocera 2013-10-23 14:55:46 UTC
Created attachment 257931 [details] [review]
gmain: Warn when g_source_remove() fails

Trying to remove a non-existent source should really be
a programming error, as the programmer could be trying to
use the wrong function to remove a callback, as seen when
GtkScrolledWindow tried to remove ID from another function
using g_source_remove().

See https://bugzilla.gnome.org/show_bug.cgi?id=710666#c12
Comment 4 Allison Karlitskaya (desrt) 2013-10-23 15:09:00 UTC
I'm no longer totally happy to commit this patch based on the fact that it regresses our own testsuite.  protocol.c does this:

      g_assert (!g_source_remove (child_source));


Which now throws a critical...


I'm not sure that there is a valid case for wanting to throw an ID that you may not own against g_source_remove() to see if it fails so maybe we should document this function as always returning TRUE except in case of programmer error and fix the tests.

I do agree that people are unlikely to check the return value here and that the critical is helpful...
Comment 5 Allison Karlitskaya (desrt) 2013-10-23 15:13:58 UTC
Created attachment 257933 [details] [review]
gmain: Warn when g_source_remove() fails

Trying to remove a non-existent source should really be
a programming error, as the programmer could be trying to
use the wrong function to remove a callback, as seen when
GtkScrolledWindow tried to remove ID from another function
using g_source_remove().

See https://bugzilla.gnome.org/show_bug.cgi?id=710666#c12
Comment 6 Allison Karlitskaya (desrt) 2013-10-23 15:14:08 UTC
Created attachment 257934 [details] [review]
gmain: test g_source_remove() with invalid ID

Make sure we get the proper critical displayed.
Comment 7 Allison Karlitskaya (desrt) 2013-10-23 15:14:12 UTC
Created attachment 257935 [details] [review]
tests: expect critical on failure to remove source

We've added a g_critical() on failure to remove sources, so make sure we
expect to see that (instead of failing the test due to the unexpected
message).
Comment 8 Allison Karlitskaya (desrt) 2013-10-23 15:14:35 UTC
This got slightly non-trivial so I'd appreciate a signoff by another maintainer.
Comment 9 Dan Winship 2013-10-23 15:41:14 UTC
(In reply to comment #4)
> I'm not sure that there is a valid case for wanting to throw an ID that you may
> not own against g_source_remove() to see if it fails

But there's probably code out there that carelessly removes the same source more than once. Eg, it attaches a source, and then maybe the source is triggered and returns FALSE, and gets destroyed, but then later on the code that originally added the source calls g_source_remove() unconditionally.

OTOH, g_signal_handler_disconnect() warns when you pass it a bad ID, so it would make sense for g_source_remove() to do so too. And on that note, I remember seeing a bug recently somewhere where someone was trying to remove a signal handler with g_source_remove()...

It's early in the release cycle. Try it and see... we can revert it later.
Comment 10 Allison Karlitskaya (desrt) 2013-10-23 16:02:11 UTC
Attachment 257933 [details] pushed as a919be3 - gmain: Warn when g_source_remove() fails
Attachment 257934 [details] pushed as b9de6f0 - gmain: test g_source_remove() with invalid ID
Attachment 257935 [details] pushed as f7beb90 - tests: expect critical on failure to remove source
Comment 11 Allison Karlitskaya (desrt) 2013-10-23 18:18:35 UTC
Created attachment 257949 [details] [review]
gtester: only remove source if not already dead

Don't attempt to g_source_remove() a source for which we already returned FALSE
from the handler.
Comment 12 Simon Feltman 2013-10-27 23:25:27 UTC
Note, the new critical caused a bit of fallout in the PyGI test suite, logged as bug 710978. The first problem is simply because we test removal of a source twice and verify the second time source.remove returns False. We simply need to silence the critical so the test suite doesn't fail.

The second failure is indeed an unnecessary call to source.remove in our MainLoop override code.

Are the docs accurate?
"Return value: For historical reasons, this function always returns %TRUE"

In addition to the critical, I'm still seeing a FALSE return, otherwise this would be an API break? Or does "It is a programmer error to attempt to remove a non-existent source." imply a FALSE return?
Comment 13 Allison Karlitskaya (desrt) 2013-10-28 18:10:01 UTC
(In reply to comment #12)
> In addition to the critical, I'm still seeing a FALSE return, otherwise this
> would be an API break? Or does "It is a programmer error to attempt to remove a
> non-existent source." imply a FALSE return?

Indeed.  This is the usual case of "violate preconditions and we violate documented behaviour".