Skip to content

adapter->discovering Status error #807

Closed as not planned
Closed as not planned

Description

@luoyuyi111

If command MGMT_OP_STOP_DISCOVERY fails we discovery_remove(client),
but we don't change the adapter->discovering,it is ture。

As a result, client found the value is true by "Discovering" property , when it starts to stop scanning again, error "No discovery started"

static void stop_discovery_complete(uint8_t status, uint16_t length,
					const void *param, void *user_data)
{
	struct btd_adapter *adapter = user_data;
	struct discovery_client *client;

	DBG("status 0x%02x", status);

	client = discovery_complete(adapter, status);
	if (client)
		discovery_remove(client);

	if (status != MGMT_STATUS_SUCCESS)
		return;

	adapter->discovery_type = 0x00;
	adapter->discovery_enable = 0x00;
	adapter->filtered_discovery = false;
	adapter->no_scan_restart_delay = false;
	adapter->discovering = false;
	g_dbus_emit_property_changed(dbus_conn, adapter->path,
					ADAPTER_INTERFACE, "Discovering");

	trigger_passive_scanning(adapter);
}
static DBusMessage *stop_discovery(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	struct btd_adapter *adapter = user_data;
	const char *sender = dbus_message_get_sender(msg);
	struct discovery_client *client;
	GSList *list;
	int err;

	DBG("sender %s", sender);

	if (!btd_adapter_get_powered(adapter))
		return btd_error_not_ready(msg);

	list = g_slist_find_custom(adapter->discovery_list, sender,
						compare_sender);
	if (!list)
		return btd_error_failed(msg, "No discovery started");

Activity

  1. github-actions commented on May 14, 2025

    @github-actions

    This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

  2. peteruithoven commented on Sep 5, 2026

    @peteruithoven

    I think I've also been experiencing the same issue. Bluetooth keyboard and mouse frequently won't re-connect to my laptop after walking away with the laptop for a while. No sleep/suspend involved. I've been debugging this with Claude for a while now.
    Manually running systemctl restart bluetooth seems to generally work to get the devices to connect again.
    While it happens frequently I can't reproduce it on command.
    I hope we can re-open this issue so we can work towards an solution.
    Since there is no "hook" for me to run this restart bluetooth automatically it's quite frustrating. Generally I walk around with my bluetooth headset, so which stays connected. So running restart bluetooth periodically also isn't an option.

    System

    • OS: elementary OS 8.1 (Ubuntu 24.04.3 LTS base)
    • Kernel: 6.16.12-061612-generic
    • BlueZ: bluetoothctl 5.72
    • Hardware: Framework 13, AMD Ryzen AI 9 HX 370
    • Adapter: Intel AX210 (combo Wi-Fi/BT), USB ID 8087:0032, driver btusb + btintel
    • Firmware: intel/ibt-0041-0041.sfi, Firmware Version 60-48.23, timestamp 2023.48 buildtype 1 build 75324, SHA1 0x23bac558

    Symptom

    Bonded Bluetooth LE HID devices (a Logitech MX Master 3S mouse and MX Keys keyboard, both address type random) intermittently fail to auto-reconnect after the adapter should be reachable again — both after real suspend/resume (s2idle) and, separately, after the laptop is simply carried out of range and back with no suspend involved at all.

    Caveat: I can't yet say whether classic/audio reconnection is equally affected. My headset travels with the laptop and stays continuously connected during these episodes (it never actually needs to reconnect), so its "staying connected" isn't evidence that classic reconnection is immune to this — I just don't have a test case for it yet. I plan to deliberately disconnect an audio device during a stuck-discovery episode to check.

    Key observation: Discovering: yes stuck with no owner

    During a live failure, the controller reported discovery as active with nothing legitimately running it:

    $ echo -e 'show\nquit' | bluetoothctl | grep -i discovering
    	Discovering: yes
    $ echo -e 'devices Connected\nquit' | bluetoothctl
    Device 7C:FE:62:9D:16:6B Fairbuds XL
    

    (keyboard/mice both bonded+trusted, both Connected: no; the one connected device here never disconnected in the first place, see caveat above)

    I suspected elementary's Bluetooth panel indicator (io.elementary.bluetooth, a D-Bus client that does its own StartDiscovery) had leaked a discovery session, but confirmed it wasn't even running at the time:

    $ pgrep -af io.elementary.bluetooth
    (no output)
    

    Discovering stayed yes regardless — ruling out a lingering client and pointing at internal adapter/daemon state rather than a reference-counting leak from a specific app. bluetoothctl scan off from a fresh session also had no effect (it can only release a session it started itself).

    Minimal reproducible fix

    A plain daemon restart — no kernel module reload, no USB re-enumeration — clears it immediately:

    $ sudo systemctl restart bluetooth
    $ echo -e 'show\nquit' | bluetoothctl | grep -i discovering
    	Discovering: no
    

    Within seconds of that, moving the mouse / pressing a key reconnected both devices normally. This matches the mechanism described in this issue: if MGMT_OP_STOP_DISCOVERY fails, discovery_remove() runs but adapter->discovering never gets reset — so it's plausible the discovery session dies (client crash, timeout, whatever) without the stop completing cleanly, leaving the flag orphaned true indefinitely, which in turn appears to block BlueZ's own background reconnect-scan for bonded LE devices.

    Related reports

    Happy to attempt to gather more (e.g. btmon capture of a live failure, SetDiscoveryFilter/StartDiscovery callers via a debug build) if that would help pin this down — let me know what would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions