GNOME Bugzilla – Bug 748642
Issue with g_source finalize callback
Last modified: 2018-05-24 17:48:21 UTC
Created attachment 302566 [details] call trace Hi! We have an issue with g_source's finalize callback. It seems that it is called from two different threads with the same source. See attachment. It also seems that this patch aaaaab91de10445a178e8183a95d98189249e868 (relevant bugid: 619329) though not causing it, triggers it very frequently. We also found this patch b358202856682e5cdefb0b4b8aaed3a45d9a85fa (relevant bug ids: 586432, 626702, 634239), which seems to be a bad idea. Every time the finalize callback called, the context lock is released and g_main_context_check->g_source_iter_next->g_source_unref_internal will be able to grab the lock immediately. (Hence the trace we have).
omg links. I hope these will be clickable: https://github.com/GNOME/glib/commit/aaaaab91de10445a178e8183a95d98189249e868 https://bugzilla.gnome.org/show_bug.cgi?id=619329 https://github.com/GNOME/glib/commit/b358202856682e5cdefb0b4b8aaed3a45d9a85fa https://bugzilla.gnome.org/show_bug.cgi?id=586432 https://bugzilla.gnome.org/show_bug.cgi?id=626702 https://bugzilla.gnome.org/show_bug.cgi?id=634239
(In reply to Tirpak Balazs from comment #0) > We also found this patch b358202856682e5cdefb0b4b8aaed3a45d9a85fa (relevant > bug ids: 586432, 626702, 634239), which seems to be a bad idea. Every time > the finalize callback called, the context lock is released and > g_main_context_check->g_source_iter_next->g_source_unref_internal will be > able to grab the lock immediately. (Hence the trace we have). Anyone that is keeping a pointer to the source needs to have their own ref on it (or at least, needs to be sure that someone else will be holding a ref on it for longer than they need to refer to it). So if the ref count has reached 0 and the finalize function gets called in one thread, that implies that no other thread should still have a pointer to that source. (In particular, in order to get the backtrace here, someone had to have called g_source_ref() on the source when it already had a ref count of 0.) I can't tell from the trace if the bug is in your code or in GLib, although the fact that no one else has hit this in the 3 years since bug 619329 was closed suggests it's probably your code. Can you come up with a simple reproducer? If not, I think this is NOTGNOME.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/glib/issues/1031.