]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: avoid crash due to race in glib event loop code
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 28 Jul 2020 15:52:47 +0000 (16:52 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Fri, 7 Aug 2020 11:43:59 +0000 (12:43 +0100)
commit0db4743645b7a0611a3c0687f834205c9956f7fc
treea1504fcdd4ddc31dffd66f075e8aaf5456087672
parentda0a1827084252d58909949d5f1207ec51c6c829
util: avoid crash due to race in glib event loop code

There is a fairly long standing race condition bug in glib which can hit
if you call g_source_destroy or g_source_unref from a non-main thread:

  https://gitlab.gnome.org/GNOME/glib/-/merge_requests/1358

Unfortunately it is really common for libvirt to call g_source_destroy
from a non-main thread. This glib bug is the cause of non-determinstic
crashes in eventtest, and probably in libvirtd too.

To work around the problem we need to ensure that we never release
the last reference on a GSource from a non-main thread. The previous
patch replaced our use of g_source_destroy with a pair of
g_source_remove and g_source_unref. We can now delay the g_source_unref
call by using a idle callback to invoke it from the main thread which
avoids the race condition.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/vireventglib.c