Package: libglib2.0-0t64
Version: 2.90.1-2
Severity: important
Tags: patch upstream
Control: tags -1 + fixed-upstream
Dear Maintainer,
Since GLib 2.89.2, GNetworkMonitorNetlink (and GNetworkMonitorNM, which
extends it) runs g_network_monitor_can_reach_async() in a GTask pool thread
(upstream commit e73abdb8, merge request 5222). That thread builds the
default GProxyResolver inside _g_io_module_get_default() while holding
default_modules_lock (gio/giomodule.c:968). When the resolver's
construction needs another GIO singleton, the thread then waits for that
singleton's GOnce: glib-networking's libproxy resolver does, because
libproxy 0.5's config-sysconfig plugin calls g_file_new_for_path(), which
waits for the GOnce of g_vfs_get_default() (gio/gvfs.c:355). If the main
thread has taken that GOnce first and needs default_modules_lock inside it
(gio/gvfs.c:359), each thread waits for the other forever.
geoclue-2.0 2.8.2 hits this at start. In on_bus_acquired(), before it asks
for its bus name, its web source calls g_network_monitor_can_reach_async()
(src/gclue-web-source.c:496) and its static source then calls
g_file_new_for_path() on the main thread (src/gclue-static-source.c:431).
The name is never requested, and systemd reports:
geoclue.service: start operation timed out. Terminating.
geoclue.service: Failed with result 'timeout'.
A program asking for the location over D-Bus waits too:
Failed to activate service 'org.freedesktop.GeoClue2': timed out
(service_start_timeout=25000ms)
It is a race. With systemd as PID 1 in a container, and Debian testing's
packages on this path (libglib2.0-0t64 2.90.1-2, geoclue-2.0 2.8.2-1,
glib-networking 2.90.0-2, libproxy1v5 0.5.12-3, network-manager),
geoclue.service timed out in 28 of 200 starts. With the patch below and
nothing else changed, 0 of 200 starts timed out. A backtrace of a hung
start shows the pool thread in can_reach_thread() holding
default_modules_lock (its pthread owner field) and waiting in
g_once_init_enter() for vfs_default_singleton, and the main thread waiting
for default_modules_lock inside g_vfs_get_default().
The two attached files reproduce it without geoclue, every time: a GIO
proxy resolver module whose construction pauses and then makes a GFile (as
libproxy's config-sysconfig plugin does), and a program that calls
g_network_monitor_can_reach_async() and then g_file_new_for_path() on its
main thread. Build lines are in each file's header; run:
GIO_EXTRA_MODULES=DIR GIO_USE_PROXY_RESOLVER=g768-slow \
GIO_USE_NETWORK_MONITOR=netlink GIO_USE_VFS=local timeout 20 ./repro
In a clean testing container: with libglib2.0-0t64 2.90.1-2 the
program printed "network monitor: GNetworkMonitorNetlink" and then hung in
10 of 10 runs, each ended by the 20 s timeout (exit 124).
With the patch below, built from Debian's source in the same container and
installed with apt: 10 of 10 runs finished in 0.61 s,
printing "g_file_new_for_path returned on the main thread" and then the
can_reach result.
Upstream fixed it. Thomas Hebb's commit "gnetworkmonitornetlink: Avoid
deadlock by creating enumerator directly in can_reach_async()" makes the
proxy address enumerator on the calling thread and keeps only the
resolution asynchronous:
https://gitlab.gnome.org/GNOME/glib/-/commit/4301b49671da484da6c305ef1050700538b33e60
(glib-2-90 branch, merge request 5460; afa628df on main, merge request 5418)
https://gitlab.gnome.org/GNOME/glib/-/work_items/4078
It is not in a tagged release yet; the newest is 2.90.1.
The debdiff below adds that commit unchanged as
debian/patches/gnetworkmonitornetlink-Avoid-deadlock-by-creating-enumerator-di.patch,
first in the series. Built with Debian's packaging on testing, GLib's
own tests (override_dh_auto_test-arch, run on the build tree) gave the
same result with and without it: 414 OK, 0 failed, 11 skipped of 425,
the same tests in each state, network-monitor, network-monitor-race,
network-address, proxy-test and gsocketclient-slow among the OK ones.
The fault came with upstream commit e73abdb8 ("gnetworkmonitornetlink:
Stop pulling all routes"), first in 2.89.2. Of Debian's versions only
2.90.1-2 (forky, sid) carries it; trixie's 2.84.4 and the 2.88 series do
not.
Related, upstream: GLib https://gitlab.gnome.org/GNOME/glib/-/work_items/4047
(the same hang, reported first, closed), and geoclue
https://gitlab.freedesktop.org/geoclue/geoclue/-/work_items/226 (open).
I found no Debian report of it.
I found this with AI assistance and checked it myself.
diff -Nru
debian.orig/patches/gnetworkmonitornetlink-Avoid-deadlock-by-creating-enumerator-di.patch
debian/patches/gnetworkmonitornetlink-Avoid-deadlock-by-creating-enumerator-di.patch
---
debian.orig/patches/gnetworkmonitornetlink-Avoid-deadlock-by-creating-enumerator-di.patch
1970-01-01 00:00:00.000000000 +0000
+++
debian/patches/gnetworkmonitornetlink-Avoid-deadlock-by-creating-enumerator-di.patch
2026-11-20 00:00:00.000000000 +0000
@@ -0,0 +1,129 @@
+From: Thomas Hebb
+Date: Sat, 17 Oct 2026 10:29:03 -0400
+Subject: gnetworkmonitornetlink: Avoid deadlock by creating enumerator
+ directly in can_reach_async()
+
+GProxyAddressEnumerator pulls in a ton of dependencies the first time
+it's created and may instantiate several singletons using GOnce and
+_g_io_module_get_default(). It's not safe to do that on a background
+thread, as _g_io_module_get_default() holds a lock that prevents the
+application from initializing a GOnce it gets to first, which in turn
+blocks the background thread from obtaining that GOnce. See the linked
+issue for a detailed analysis.
+
+Create GProxyAddressEnumerator synchronously while still keeping the
+resolution asynchronous, like we already do in GNetworkMonitorBase.
+
+Fixes: https://gitlab.gnome.org/GNOME/glib/-/work_items/4078
+
+Origin: upstream,
https://gitlab.gnome.org/GNOME/glib/-/commit/4301b49671da484da6c305ef1050700538b33e60
+Applied-upstream: glib-2-90 branch,
commit:4301b49671da484da6c305ef1050700538b33e60 (merge request 5460); main,
commit:afa628dfbd636b702009e8be2f916325380fa6d0 (merge request 5418)
+Bug: https://gitlab.gnome.org/GNOME/glib/-/work_items/4078
+Bug: https://gitlab.gnome.org/GNOME/glib/-/work_items/4047
+Bug: https://gitlab.freedesktop.org/geoclue/geoclue/-/work_items/226
+---
+ gio/gnetworkmonitornetlink.c | 73 ++++++++++++++++++++++++++++--------
+ 1 file changed, 58 insertions(+), 15 deletions(-)
+
+diff --git a/gio/gnetworkmonitornetlink.c b/gio/gnetworkmonitornetlink.c
+index 5532a1406a..3bffe23eeb 100644
+--- a/gio/gnetworkmonitornetlink.c
++++ b/gio/gnetworkmonitornetlink.c
+@@ -913,19 +913,62 @@ g_network_monitor_netlink_can_reach (GNetworkMonitor
*monitor,
+ }
+
+ static void
+-can_reach_thread (GTask *task,
+- gpointer source_object,
+- gpointer task_data,
+- GCancellable *cancellable)
++can_reach_async_got_address (GObject *object,
++ GAsyncResult *result,
++ gpointer user_data)
+ {
+- GNetworkMonitor *monitor = G_NETWORK_MONITOR (source_object);
+- GSocketConnectable *connectable = G_SOCKET_CONNECTABLE (task_data);
++ GSocketAddressEnumerator *enumerator = G_SOCKET_ADDRESS_ENUMERATOR (object);
++ GTask *task = user_data;
++ GNetworkMonitor *monitor = G_NETWORK_MONITOR (g_task_get_source_object
(task));
++ GNetworkMonitorNetlink *nl = G_NETWORK_MONITOR_NETLINK (monitor);
++ GCancellable *cancellable = g_task_get_cancellable (task);
++ GSocketAddress *addr;
+ GError *error = NULL;
+
+- if (g_network_monitor_netlink_can_reach (monitor, connectable, cancellable,
&error))
+- g_task_return_boolean (task, TRUE);
+- else
+- g_task_return_error (task, g_steal_pointer (&error));
++ addr = g_socket_address_enumerator_next_finish (enumerator, result, &error);
++ if (!addr && !error)
++ {
++ /* Resolved all addresses, none matched */
++ g_task_return_new_error_literal (task, G_IO_ERROR,
++ G_IO_ERROR_HOST_UNREACHABLE,
++ _("Host unreachable"));
++ g_object_unref (task);
++ return;
++ }
++
++ if (G_IS_INET_SOCKET_ADDRESS (addr))
++ {
++ GInetAddress *iaddr;
++
++ iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS
(addr));
++ if (route_get (nl, iaddr, cancellable, &error))
++ {
++ g_object_unref (addr);
++ g_task_return_boolean (task, TRUE);
++ g_object_unref (task);
++ return;
++ }
++
++ if (!g_cancellable_is_cancelled (cancellable))
++ {
++ g_clear_error (&error);
++ }
++ }
++
++ if (addr)
++ g_object_unref (addr);
++
++ if (error)
++ {
++ /* Either the user cancelled, or DNS resolution failed */
++ g_task_return_error (task, error);
++ g_object_unref (task);
++ return;
++ }
++
++ g_socket_address_enumerator_next_async (enumerator,
++ g_task_get_cancellable (task),
++ can_reach_async_got_address, task);
+ }
+
+ static void
+@@ -936,16 +979,16 @@ g_network_monitor_netlink_can_reach_async
(GNetworkMonitor *monitor,
+ gpointer user_data)
+ {
+ GTask *task;
++ GSocketAddressEnumerator *enumerator;
+
+ task = g_task_new (monitor, cancellable, callback, user_data);
+ g_task_set_source_tag (task, g_network_monitor_netlink_can_reach_async);
+ g_task_set_static_name (task, "[gio] network monitor can_reach");
+- g_task_set_task_data (task, g_object_ref (connectable), g_object_unref);
+
+- /* A route lookup is a quick kernel round-trip, so the shared GTask thread
+- * pool is fine here. */
+- g_task_run_in_thread (task, can_reach_thread);
+- g_object_unref (task);
++ enumerator = g_socket_connectable_proxy_enumerate (connectable);
++ g_socket_address_enumerator_next_async (enumerator, cancellable,
++ can_reach_async_got_address, task);
++ g_object_unref (enumerator);
+ }
+
+ static gboolean
+--
+GitLab
+
diff -Nru debian.orig/patches/series debian/patches/series
--- debian.orig/patches/series 2026-10-07 13:45:14.000000000 +0000
+++ debian/patches/series 2026-11-20 00:00:00.000000000 +0000
@@ -1,3 +1,4 @@
+gnetworkmonitornetlink-Avoid-deadlock-by-creating-enumerator-di.patch
01_gettext-desktopfiles.patch
debian/02_gettext-desktopfiles-ubuntu.patch
debian/03_disble_glib_compile_schemas_warning.patch
-- System Information:
Debian Release: forky/sid
APT prefers testing
APT policy: (500, 'testing')
Architecture: amd64 (x86_64)
Kernel: Linux 7.3.4-stereo3d18 (SMP w/12 CPU threads; PREEMPT)
Kernel taint flags: TAINT_WARN, TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=C, LC_CTYPE=C.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: unable to detect
Versions of packages libglib2.0-0t64 depends on:
ii libatomic1 16.2.0-4
ii libc6 2.43-7
ii libffi8 3.8.0-2
ii libmount1 2.42.4-1
ii libpcre2-8-0 10.49-1
ii libselinux1 3.11-2.1+b1
ii zlib1g 1:1.3.dfsg+really1.3.2-4
Versions of packages libglib2.0-0t64 recommends:
ii libglib2.0-data 2.90.1-2
pn shared-mime-info <none>
pn xdg-user-dirs <none>
Versions of packages libglib2.0-0t64 suggests:
pn low-memory-monitor <none>
-- no debconf information
/* Reproducer: what geoclue 2.8.2 does at start, in a dozen lines.
*
* gclue_web_source_constructed() calls g_network_monitor_can_reach_async(); a
moment later
* gclue_static_source's check_monitor() calls g_file_new_for_path() on the
main thread.
* With GLib 2.90.1's GNetworkMonitorNetlink, can_reach_async() builds the
proxy enumerator on a
* pool thread; with the slow resolver module that thread holds
default_modules_lock while the
* main thread takes the GOnce of g_vfs_get_default(), and each waits for the
other.
*
* Build: gcc -o repro repro.c $(pkg-config --cflags --libs gio-2.0)
* Run: GIO_EXTRA_MODULES=DIR GIO_USE_PROXY_RESOLVER=g768-slow
GIO_USE_NETWORK_MONITOR=netlink \
* GIO_USE_VFS=local timeout 20 ./repro
* Exit: 0 when the main thread got its GFile and the check finished; 124
(from timeout) when it hung.
*/
#include <gio/gio.h>
static void
reach_done (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
GError *error = NULL;
gboolean reachable = g_network_monitor_can_reach_finish (G_NETWORK_MONITOR
(source), result, &error);
g_print ("can_reach finished: %s%s\n", reachable ? "reachable" : "not
reachable: ",
error ? error->message : "");
g_clear_error (&error);
g_main_loop_quit (user_data);
}
int
main (void)
{
GMainLoop *loop = g_main_loop_new (NULL, FALSE);
GNetworkMonitor *monitor = g_network_monitor_get_default ();
GSocketConnectable *address = g_network_address_parse_uri
("https://g768.invalid/", 443, NULL);
GFile *file;
g_print ("network monitor: %s\n", G_OBJECT_TYPE_NAME (monitor));
g_network_monitor_can_reach_async (monitor, address, NULL, reach_done, loop);
g_usleep (G_USEC_PER_SEC / 10);
file = g_file_new_for_path ("/etc/geolocation");
g_print ("g_file_new_for_path returned on the main thread\n");
g_object_unref (file);
g_main_loop_run (loop);
g_object_unref (address);
g_main_loop_unref (loop);
return 0;
}
/* A GIO proxy resolver module for the reproducer (repro.c).
*
* Its construction does what libproxy's config-sysconfig plugin does inside
glib-networking's
* GLibproxyResolver: it makes a GFile (so it needs g_vfs_get_default()), after
a pause that lets
* the application reach g_vfs_get_default() first. GIO constructs the default
resolver inside
* _g_io_module_get_default(), with default_modules_lock held.
*
* Build: gcc -shared -fPIC -o libg768slowproxy.so slowproxy.c $(pkg-config
--cflags --libs gio-2.0)
* Use: GIO_EXTRA_MODULES=DIR GIO_USE_PROXY_RESOLVER=g768-slow
*/
#include <gio/gio.h>
typedef struct { GObject parent; } G768SlowProxy;
typedef struct { GObjectClass parent_class; } G768SlowProxyClass;
static void g768_slow_proxy_iface_init (GProxyResolverInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (G768SlowProxy, g768_slow_proxy, G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC
(G_TYPE_PROXY_RESOLVER,
g768_slow_proxy_iface_init))
static void
g768_slow_proxy_init (G768SlowProxy *self)
{
GFile *file;
g_usleep (G_USEC_PER_SEC / 2);
file = g_file_new_for_path ("/etc/sysconfig/proxy");
g_object_unref (file);
}
static void
g768_slow_proxy_class_init (G768SlowProxyClass *klass)
{
}
static void
g768_slow_proxy_class_finalize (G768SlowProxyClass *klass)
{
}
static gboolean
g768_slow_proxy_is_supported (GProxyResolver *resolver)
{
return TRUE;
}
static gchar **
g768_slow_proxy_lookup (GProxyResolver *resolver,
const gchar *uri,
GCancellable *cancellable,
GError **error)
{
gchar **proxies = g_new0 (gchar *, 2);
proxies[0] = g_strdup ("direct://");
return proxies;
}
static void
g768_slow_proxy_lookup_async (GProxyResolver *resolver,
const gchar *uri,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task = g_task_new (resolver, cancellable, callback, user_data);
g_task_return_pointer (task, g768_slow_proxy_lookup (resolver, uri,
cancellable, NULL),
(GDestroyNotify) g_strfreev);
g_object_unref (task);
}
static gchar **
g768_slow_proxy_lookup_finish (GProxyResolver *resolver,
GAsyncResult *result,
GError **error)
{
return g_task_propagate_pointer (G_TASK (result), error);
}
static void
g768_slow_proxy_iface_init (GProxyResolverInterface *iface)
{
iface->is_supported = g768_slow_proxy_is_supported;
iface->lookup = g768_slow_proxy_lookup;
iface->lookup_async = g768_slow_proxy_lookup_async;
iface->lookup_finish = g768_slow_proxy_lookup_finish;
}
G_MODULE_EXPORT void
g_io_module_load (GIOModule *module)
{
g_type_module_use (G_TYPE_MODULE (module));
g768_slow_proxy_register_type (G_TYPE_MODULE (module));
g_io_extension_point_implement (G_PROXY_RESOLVER_EXTENSION_POINT_NAME,
g768_slow_proxy_get_type (), "g768-slow", 0);
}
G_MODULE_EXPORT void
g_io_module_unload (GIOModule *module)
{
}