Skip to content

🐛 Multi ReadCharacteristic Value Race Condition on iOS #1316

@andrewcharnley

Description

@andrewcharnley

Prerequisites

  • I checked the documentation and FAQ without finding a solution
  • I checked to make sure that this issue has not already been filed

Expected Behavior

On iOS with 3.50 calls to readcharacteristic sometimes return the value for a different characteristic. While I haven't looked at the Java I suspect it's returning the Promise early and the next iteration is then conflicting. If readCharacteristic should support parallel async calls then the internal code must have an issue, but here I am sequencing them.

It's only occurring on iOS and only sometimes but this will be down to timing/race. I've also tried the Promise patch file from the other PR. I didn't see this or have it reported by users on 3.2.* and will roll back.

Here's the code I have which will occasionally return the value for a different characteristic. I've verified with a user when it occurs the value returned for one characteristic is actually the value for another.

      for (const { name, uuid } of service.characteristics
         .filter(({ read }) => read)) {
              const {value} = await device.readCharacteristicForService(service.uuid, uuid);
              const output = ret.characteristics[name];
              const buffer = decodeBase64(value);
              output.bufferLength = buffer.length;
              addDebug(`Read ${name} of length ${buffer.length}`);
        
...

Current Behavior

It's unreliable.

Library version

3.5.0

Device

iOS

Environment info

N/A

Steps to reproduce

N/A

Formatted code sample or link to a repository

No

Relevant log output

N/A

Additional information

No response

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