Skip to content

[Issue] PairAsync() random HANGS #78

Description

@beavis88

I have many BLE devices based on nRF chips, and they use simple Just Works pairing. I wrote an application based on the agent example from the Linux.Bluetooth repository that connects to and pairs with a device, and very often it gets stuck indefinitely on await device.PairAsync().

After restarting the application, the pairing always completes successfully. This is very bad behavior — there should never be any hangs under any circumstances. It’s also problematic that the async functions do not accept cancellation tokens or timeouts.

I used Linux.Bluetooth development (pre4) and BlueZ 5.54.
Previously, I observed the same behavior on pre3 and on stable 5.67 as well.

Another issue is that pairing is lost after a reboot or even after the application exits. Does this library even attempt to persist pairing information?

Here my steps:

agent setup:
...
var agent = await BlueZManager.CreateAgentAsync(connection, "NoInputNoOutput");
agent.PinCodeRequested += (_, ) => Task.FromResult("");
agent.PasskeyRequested += (
, ) => Task.FromResult((uint)0);
agent.ConfirmationRequested += (
, ) => Task.CompletedTask;
agent.AuthorizationRequested += (
, ) => Task.CompletedTask;
agent.ServiceAuthorizationRequested += (
, ) => Task.CompletedTask;
agent.PinCodeDisplayed += (
, ) => Task.CompletedTask;
agent.PasskeyDisplayed += (
, ) => Task.CompletedTask;
agent.OperationCancelled += (
, _) => Task.CompletedTask;
...

BLE scan
...
connection:

var device = await BluetoothAdapter.Instance.Adapter.GetDeviceAsync(deviceAddress);
await device.ConnectAsync();
await device.WaitForPropertyValueAsync("Connected", true, ConnectionTimeout);
await device.PairAsync(); <--- infinite hang
await device.WaitForPropertyValueAsync("Paired", true, PairingTimeout);

Metadata

Metadata

Assignees

No one assigned

    Labels

    not-reviewedIssue that needs reviewed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions