Thizzer
Thizzer

Reputation: 16663

BlueZ over DBus stops responding within varying intervals

I am currently using the BlueZ DBus API to scan for BLE devices but it stops responding completely after varying intervals. Sometimes it's minutes, other times it's one or two hours.

My assumption is that I am forgetting to do something. The strange thing is, that after I exit the application, tools like bluetoothctl and hciconfig also no longer respond. Sometimes a reboot is not enough to get it to work again and I need to power-cycle the machines. It happens on several different machines as well.

I am acquiring the bus using:

GError* error = nullptr;
mConnection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error);

Starting the loop:

mLoop = g_main_loop_new(nullptr, false);
g_main_loop_run(mLoop); 

Then I power on the adapter by setting the Powered property to true and calling StartDiscovery. Devices are then reported through:

guint iface_add_sub = g_dbus_connection_signal_subscribe(mConnection, "org.bluez", "org.freedesktop.DBus.ObjectManager", "InterfacesAdded", nullptr, nullptr, G_DBUS_SIGNAL_FLAGS_NONE, device_appeared, this, nullptr);

guint iface_remove_sub
        = g_dbus_connection_signal_subscribe(mConnection, "org.bluez", "org.freedesktop.DBus.ObjectManager", "InterfacesRemoved", nullptr, nullptr, G_DBUS_SIGNAL_FLAGS_NONE, device_disappeared, this, nullptr);

Is there anything I am missing to prevent BlueZ from stopping to respond?

Upvotes: 0

Views: 679

Answers (1)

Martijn van Welie
Martijn van Welie

Reputation: 754

Bluez cannot scan indefinitely because it will crash, as you are observing. In my opinion it is a bug…

What I do is to scan for 8 seconds and then stop the scan. Bluez will then clean up internal cache. After allowing 1 second for cleanup, I restart the scan.

This way it will hold up much longer. Nonetheless after a week or so it might still crash…

Upvotes: 1

Related Questions