question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android 10 - startNotification gives error "Error writing descriptor stats=133"

See original GitHub issue

Version

  • react-native-ble-manager v7.4.1
  • react-native v0.63.4
  • iOS/Android v.10 kernel 4.19.95

Expected behaviour

startNotification should start notification on characteristic

Actual behaviour

Gives error: Error writing descriptor stats=133

Code to reproduce

AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

App.js

  const connect = async device => {
    await BleManager.connect(device.id)
    console.log('Connected......')
    const info = await BleManager.retrieveServices(device.id)
    console.log('Got service...', info)
    const characteristic = info.characteristics[3]
    const service = characteristic.service
    const charect = characteristic.characteristic
    console.log(service, charect)
    setTimeout(async () => {
      await BleManager.startNotification(device.id, service, charect)
      debugger
      await BleManager.disconnect(device.id)
      console.log('Disonnected......')
    }, 500)
  }

Stack trace and console log

{advertising: {…}, rssi: -56, id: "04:91:62:93:03:59", name: "MyDevice"}
App.js:65 Connected......
App.js:67 Got service... {characteristics: Array(4), services: Array(3), advertising: {…}, name: "MyDevice", rssi: -56, …}
App.js:71 11020304-0506-0708-0900-0a0b0c0d0e0f 11223344-5566-7788-9900-aabbccddeeff
backend.js:32 Possible Unhandled Promise Rejection (id: 0):
"Error writing descriptor stats=133"
...

Could it be the new UBSan (Bounds Sanitizer) in Android 10? https://source.android.com/devices/tech/debug/bounds-sanitizer

signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'ubsan: out-of-bounds'

It here in Peripheral.java where it fails: (line 501)

if (gatt.writeDescriptor(descriptor)) {
    Log.d(BleManager.LOG_TAG, "setNotify complete");
} else {
    registerNotifyCallback = null;
    callback.invoke(
        "Failed to set client characteristic notification for " + characteristicUUID);
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DomLeMarincommented, Aug 30, 2021

I had the same issue with the phone OPPO A53 (ColorOS 7.2 based on Android 10). After struggling on it for several days, I found out that I need to create a bond first and then it works (I never had to do that with any other Android phones).

After catching the error stats=133, the following seems to work:

  1. Wait until the device is truly disconnected (about 10 sec),
  2. Call the function BleManager.createBond(peripheral.id),
  3. Accept the pairing pop-up that shows up on the screen,
  4. Wait until the device is truly disconnected (about 25 sec),
  5. Start again with BleManager.connect, BleManager.retrieveServices, BleManager.startNotification

This needs to be done only once. The next connections are working as usual, since the two devices are bonded.

I hope it helps someone…

0reactions
jimhufcommented, Jul 27, 2021

I have this same problem, on a Samsung note 10 Android 11 (Kernel 4.14) But works fine on Android 11 (Kernel 4.9) Galaxy Tab S5e

Any update on this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

startNotification gives error "Error writing descriptor stats=133"
Android 10 - startNotification gives error "Error writing descriptor stats=133"
Read more >
BLE notification subscription gets 133 - Stack Overflow
Note: if I'm using the native Android API, I'm able to subscribe and receive notifications without having to write into the descriptor. update: ......
Read more >
Error on writing characteristic (133) - Nordic Q&A
Hi. I'm testing the nRF Toolbox for Android. But I get this error when I try to connect using the proximity feature: image...
Read more >
RxBLELibraries/react-native-ble - Gitter
js, but I get the error Cannot write to descriptor 00002902-0000-1000-8000-00805f9b34fb. It's not allowed by iOS and therefore forbidden on Android as well...
Read more >
Broken pipe - Error writing to file descriptor - Red Hat Bugzilla
Description of problem: While using evolution clipboard stops working and the journal is flooded with this error Error writing selection data: Error writing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found