From 3d50691a30270de8c880a5ad6b0be2f8ec36a673 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 4 Apr 2018 08:35:39 +0100 Subject: [PATCH] g_test_dbus_down: Ensure next test does not use old connection There's a race condition somewhere in GTestDBus that can result in the next test being started at a time when g_bus_get() would still return the connection that is in the process of closing. This can be reproduced reasonably reliably by running the gapplication test 10K times in a loop. Instead of relying on waiting for the weak reference to be released, we can force the issue by clearing it. Bug: https://bugzilla.gnome.org/show_bug.cgi?id=768996 Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=894677 --- gio/gdbusconnection.c | 16 ++++++++++++++++ gio/gdbusprivate.h | 1 + gio/gtestdbus.c | 1 + 3 files changed, 18 insertions(+) diff --git a/gio/gdbusconnection.c b/gio/gdbusconnection.c index 6f7e5fefc..2c74a73b3 100644 --- a/gio/gdbusconnection.c +++ b/gio/gdbusconnection.c @@ -7233,6 +7233,22 @@ _g_bus_get_singleton_if_exists (GBusType bus_type) return ret; } +/* May be called from any thread. Must not hold message_bus_lock. */ +void +_g_bus_forget_singleton (GBusType bus_type) +{ + GWeakRef *singleton; + + G_LOCK (message_bus_lock); + + singleton = message_bus_get_singleton (bus_type, NULL); + + if (singleton != NULL) + g_weak_ref_set (singleton, NULL); + + G_UNLOCK (message_bus_lock); +} + /** * g_bus_get_sync: * @bus_type: a #GBusType diff --git a/gio/gdbusprivate.h b/gio/gdbusprivate.h index 21f2d5e5c..0d85c1d85 100644 --- a/gio/gdbusprivate.h +++ b/gio/gdbusprivate.h @@ -146,6 +146,7 @@ gchar *_g_dbus_hexencode (const gchar *str, /* Implemented in gdbusconnection.c */ GDBusConnection *_g_bus_get_singleton_if_exists (GBusType bus_type); +void _g_bus_forget_singleton (GBusType bus_type); G_END_DECLS diff --git a/gio/gtestdbus.c b/gio/gtestdbus.c index 6eaf060d9..227f5b2ea 100644 --- a/gio/gtestdbus.c +++ b/gio/gtestdbus.c @@ -823,6 +823,7 @@ g_test_dbus_down (GTestDBus *self) _g_object_dispose_and_wait_weak_notify (connection); g_test_dbus_unset (); + _g_bus_forget_singleton (G_BUS_TYPE_SESSION); self->priv->up = FALSE; } -- 2.11.4.GIT