GDBusConnection is closed right after successful creation

I’m writing an audio plugin and I’m using GLib/GIO to communicate with DBus. To do so, I create a new GThread, inside of which I create a new GMainContext, push it as the thread default context, create a new GMainLoop in that context, and run the loop. Then I create a new bus connection with g_bus_get, and the connection gets created without and errors with g_bus_get_finish. But running g_dbus_connection_is_closed right after returns 1, so I have no idea what’s going on.

If you want to try the code, you can load the plugin in Carla and look in the Logs tab.

The standard session bus is cached globally and a call to g_bus_get() will return the cached version if it exists. If something else in the process has previously closed the cached connection, that might explain what you’re seeing.

Could that be the case?

If you want to create a new connection, rather than reusing the cached one, call g_dbus_connection_new_for_address() with the session bus address (use g_dbus_address_get_for_bus_sync()). There’s a (synchronous, not asynchronous) example here.

1 Like

Ah yes, that works. Thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.