Skip to content

WinRT: DashMap guard held across .await in GATT ops can deadlock #481

Description

@qdot

In src/winrtble/peripheral.rs (write, read, subscribe, unsubscribe, read_descriptor, write_descriptor), the service lookup is written as:

let ble_service = &*self.shared.ble_services.get(&characteristic.service_uuid).ok_or_else(...)?;

Temporary lifetime extension keeps the DashMap Ref/RefMut guard alive until the end of the function, so the shard lock is held across ble_characteristic.write_value(..).await / .subscribe(..).await etc. DashMap locks are blocking, not async-aware.

Failure scenario: futures::join!(p.subscribe(&a), p.subscribe(&b)) with a, b in the same service: the first future holds the write lock while awaiting the CCCD write; the second blocks the thread in get_mut, so the first can never be polled again. Permanent deadlock. Also reachable on a current-thread runtime with any concurrent op + subscribe, or disconnect() (ble_services.clear()) racing an in-flight op.

Fix direction: clone what's needed (the characteristic handle) out of the map and drop the guard before awaiting.

Activity

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

    bugSomething isn't workinguwp (windows)Issues related to the UWP/Win10 core

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions