react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

ERROR Invariant Violation: No callback found with version 8.4.3

Open fabianbru opened this issue 3 years ago • 1 comments

Describe the bug If the device is disconnected on write the app crashes with:

Metro logs:

Invariant Violation: No callback found with cbID 18325 and callID 9162 for  BleManager.write - most likely the callback was already invoked. Args: '["Device disconnected"]', js engine: hermes

LogCat output:

FATAL EXCEPTION: main
Process: <redacted:bundleId>, PID: 16050
java.lang.RuntimeException: Illegal callback invocation from native module. This callback type only permits a single invocation from native code.
	at com.facebook.react.bridge.CallbackImpl.invoke(CallbackImpl.java:26)
	at it.innove.Peripheral$6.run(Peripheral.java:681)
	at android.os.Handler.handleCallback(Handler.java:938)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:201)
	at android.os.Looper.loop(Looper.java:288)
	at android.app.ActivityThread.main(ActivityThread.java:7870)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

It looks like the issue from https://github.com/innoveit/react-native-ble-manager/issues/885 but on writing data. Or perhaps the issue is not fixed completely? So I added a try/catch block:

JS Code with try/catch:

    try {
      return await this.manager.write(deviceId, serviceUUID, characteristicUUID, valueByteArray, 512)
    } catch (e) {
      console.log('write failed', e)
    }

Metro logs with try/catch:

write failed Device disconnected

Edit: sometimes I get:

write failed Error writing <redacted:deviceId> status=133

without App crash. So timing is also a thing.

But LogCat output is the same and the app is still crashing.

To Reproduce

  1. write data (with response)
  2. disconnect device (e.g. by removing battery)

Expected behavior A catchable exception without crash.

Smartphone (please complete the following information):

  • Device: Pixel 3a
  • OS: android 12
  • react-native-ble-manager version: 8.4.3
  • react-native version: 0.69.5

fabianbru avatar Sep 02 '22 09:09 fabianbru

facing same issue on android 12. Tried adding try catch, but will hitting error

ManigandanRaamanathan avatar Sep 06 '22 16:09 ManigandanRaamanathan

We are on v8.4.3 of this plugin, and I think we're experiencing this error as well. We cannot reproduce this locally so far, but we have customer reports of this on android 12 and 13. We don't have very good visibility into the problem beyond this stack trace:

java.lang.RuntimeException: Illegal callback invocation from native module. This callback type only permits a single invocation from native code.
  at com.facebook.react.bridge.CallbackImpl.invoke(CallbackImpl.java:25)
  at it.innove.Peripheral$6.run(Peripheral.java:666)
  at android.os.Handler.handleCallback(Handler.java:942)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loopOnce(Looper.java:201)
  at android.os.Looper.loop(Looper.java:288)
  at android.app.ActivityThread.main(ActivityThread.java:7898)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

react-native version: 0.61.5 Device: Google raven

kevinswartz avatar Oct 24 '22 19:10 kevinswartz

i have the same issue. i've tried catching this in js & java... impossible for now. the error comes to the UI 😵‍💫

Koxx3 avatar Nov 12 '22 23:11 Koxx3

ok, i've think I've found something. the callback is not reset after sendBackrError() is called. then the callback is called an second time when the onConnectionStateChange() loop on the callback to clear all pending callbacks.

Koxx3 avatar Nov 13 '22 10:11 Koxx3

you can try my fix with :

yarn remove react-native-ble-manager
yarn add Koxx3/react-native-ble-manager.git

if it works for you too, i'll make a pull request. it fixed the issue for me with read & write interrupted without BLE device answer.

Koxx3 avatar Nov 13 '22 10:11 Koxx3

works great for me ... so I pushed the PR : https://github.com/innoveit/react-native-ble-manager/pull/923

Koxx3 avatar Nov 13 '22 10:11 Koxx3

works great for me ... so I pushed the PR : #923

This fixed the issue for me as well. Thank you!

traviswsims avatar Nov 14 '22 21:11 traviswsims

ahhhh ! cool !

Koxx3 avatar Nov 14 '22 22:11 Koxx3