On Tue, 18 May 2021 at 05:38:29 +0000, Mike Gabriel wrote: > I have Cc: Adrian Bunk as he had some good ideas in the past on such issues. > Adrian, do you mind taking a look? Any hint how to track this issue down?
Adrian asked me on IRC and was concerned about whether https://sources.debian.org/src/dbus-test-runner/16.10.0%7Ebzr100+repack1-4.1/tests/test-libdbustest-mock.c/#L35 is thread-safe: g_object_add_weak_pointer(G_OBJECT(connection), (gpointer) &wait_for_close_ptr); I think he is correct to be concerned about this. As documented, g_object_add_weak_pointer() cannot be thread-safe for historical reasons. See <https://bugzilla.gnome.org/show_bug.cgi?id=548954> for details. A better way to implement this would be to use a GWeakRef, which is the mechanism that was added to GLib to provide thread-safe weak-refs. Unlike g_object_add_weak_pointer(), GWeakRef triggers before dispose() (whereas g_object_add_weak_pointer() triggers after dispose() but before finalize()), and is not tied up with g_object_weak_ref() (which calls an arbitrary user-supplied callback that can't really be thread-safe). Something like this (untested!): GWeakRef weak; g_weak_ref_init (&weak, connection); g_object_unref (connection); int wait_count; for (wait_count = 0; wait_count < SESSION_MAX_WAIT; wait_count++) { GDBusConnection *still_alive = g_weak_ref_get (&weak); if (still_alive == NULL) break; g_object_unref (still_alive); process_mainloop(200); } g_weak_ref_clear (&weak); g_assert (wait_count != SESSION_MAX_WAIT); (This is basically a more complicated version of g_assert_finalize_object() that assumes the object is temporarily being kept alive by references held in the default main-context, and therefore polls the default main-context instead of just asserting that the object dies immediately.) The good news is that if this change fixes the autopkgtest, then it was a bug in the test, and not a bug in the parts of dbus-test-runner that are used by other packages. smcv