Skip to content

Potential bug in BLEClient disconnected_callback registration #770

@williballenthin

Description

@williballenthin

When investigating why my node sometime ends up in a still-connected state, despite my script crashing (like described here), I came across this line:

client = BLEClient(device.address, disconnected_callback=lambda _: self.close)

context:

        # Bleak docs recommend always doing a scan before connecting (even if we know addr)
        device = self.find_device(address)
        client = BLEClient(device.address, disconnected_callback=lambda _: self.close)
        client.connect()
        client.discover()
        return client

Should this be:

client = BLEClient(device.address, disconnected_callback=lambda _: self.close())

Note that the lambda actually invokes the method, rather than returning it. According to the documentation, it does seem like the disconnected_callback should be a function expecting one argument that will be invoked (rather than to return the handler). So, I suspect this is a bug. Can you confirm?

cc: @thebentern and @geeksville as the last people to touch the line in #616

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions