hyperledger-archives / indy-sdk

indy-sdk
https://wiki.hyperledger.org/display/indy
Apache License 2.0
669 stars 739 forks source link

RN Android crash, probably zmq issue #2346

Closed adamblack closed 5 months ago

adamblack commented 3 years ago

Hello,

we are having issues with indy-sdk on React native, Android - issue does not depend on the device.

This is our deps setup for example project:

"dependencies": {
   "react": "16.11.0",
   "react-native": "0.62.2",
   "react-native-fs": "^2.16.6",
   "rn-indy-sdk": "^0.1.7"
 },

RN wrapper uses these methods:

@ReactMethod
   public void createPoolLedgerConfig(String configName, String poolConfig, Promise promise) {
       try {
           Pool.createPoolLedgerConfig(configName, poolConfig).get();
           promise.resolve(null);
       } catch (Exception e) {
           IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
           promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
       }
   }

   @ReactMethod
   public void openPoolLedger(String configName, String poolConfig, Promise promise) {
       try {
           Pool pool = Pool.openPoolLedger(configName, poolConfig).get();
           poolMap.put(pool.getPoolHandle(), pool);
           promise.resolve(pool.getPoolHandle());
       } catch (Exception e) {
           IndySdkRejectResponse rejectResponse = new IndySdkRejectResponse(e);
           promise.reject(rejectResponse.getCode(), rejectResponse.toJson(), e);
       }
   }

And this dependency for indy:

implementation 'org.hyperledger:indy:1.15.0'

We also opened an issue for RN at: https://github.com/react-native-community/upgrade-support/issues/114

Issue is not reproducible on 0.61.x RN version. Below you can find our logs. It seems to us it might be connected to zmq somehow. We are thinking about making our custom build of indy-sdk with a different version of zmq which might somehow help us however it would be better to fix this issue in official repo, not just in a forked one.

Lsun/misc/Unsafe;->allocateInstance(Ljava/lang/Class;)Ljava/lang/Object; (greylist, reflection, allowed) 01-05 16:23:22.988 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.commands - src/commands/mod.rs:142 | PoolCommand command received 01-05 16:23:22.992 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.pool_command_executor - src/commands/pool.rs:132 | SetProtocolVersion command received 01-05 16:23:22.995 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.commands.pool - src/commands/pool.rs:225 | set_protocol_version >>> version: 2 01-05 16:23:22.999 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.commands.pool - src/commands/pool.rs:233 | set_protocol_version <<< 01-05 16:23:23.024 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.commands - src/commands/mod.rs:142 | PoolCommand command received 01-05 16:23:23.027 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.pool_command_executor - src/commands/pool.rs:71 | Open command received 01-05 16:23:23.028 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.commands.pool - src/commands/pool.rs:159 | open >>> name: "default_pool", config: None 01-05 16:23:23.033 4234 4328 W System.err: [Thread-4] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.commands.pool - src/commands/pool.rs:173 | open <<< 01-05 16:23:23.104 4234 4331 W System.err: [Thread-5] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.services.pool.pool - src/services/pool/pool.rs:701 | Error during retrieving nodes: IndyError { inner: 01-05 16:23:23.104 4234 4331 W System.err: 01-05 16:23:23.104 4234 4331 W System.err: Node is not a validator 01-05 16:23:23.104 4234 4331 W System.err: 01-05 16:23:23.104 4234 4331 W System.err: Invalid library state } 01-05 16:23:23.106 4234 4331 W System.err: [Thread-5] DEBUG … … ... org.hyperledger.indy.sdk.LibIndy.native.indy.services.pool.pool - src/services/pool/pool.rs:701 | Error during retrieving nodes: IndyError { inner: 01-05 16:23:23.140 4234 4331 W System.err: 01-05 16:23:23.140 4234 4331 W System.err: Node is not a validator 01-05 16:23:23.140 4234 4331 W System.err: 01-05 16:23:23.140 4234 4331 W System.err: Invalid library state } 01-05 16:23:23.148 4234 4331 W System.err: [Thread-5] DEBUG org.hyperledger.indy.sdk.LibIndy.native.indy.services.pool.networker - src/services/pool/networker.rs:333 | _get_socket: open new socket for node 0 01-05 16:23:23.150 4234 4331 F libc : Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 4331 (Thread-5), pid 4234 (com.versiontest) 01-05 16:23:23.206 4336 4336 I crash_dump64: obtaining output fd from tombstoned, type: kDebuggerdTombstone 01-05 16:23:23.207 840 840 I /system/bin/tombstoned: received crash request for pid 4331 01-05 16:23:23.207 4336 4336 I crash_dump64: performing dump of process 4234 (target tid = 4331) 01-05 16:23:23.223 4336 4336 F DEBUG : 01-05 16:23:23.223 4336 4336 F DEBUG : Build fingerprint: 'google/sailfish/sailfish:10/QP1A.191005.007.A3/5972272:user/release-keys' 01-05 16:23:23.223 4336 4336 F DEBUG : Revision: '0' 01-05 16:23:23.223 4336 4336 F DEBUG : ABI: 'arm64' 01-05 16:23:23.224 4336 4336 F DEBUG : Timestamp: 2021-01-05 16:23:23+0100 01-05 16:23:23.224 4336 4336 F DEBUG : pid: 4234, tid: 4331, name: Thread-5 >>> com.versiontest <<< 01-05 16:23:23.224 4336 4336 F DEBUG : uid: 11405 01-05 16:23:23.224 4336 4336 F DEBUG : signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- 01-05 16:23:23.224 4336 4336 F DEBUG : x0 0000000000000000 x1 00000000000010eb x2 0000000000000006 x3 00000078c4fc9d60 01-05 16:23:23.224 4336 4336 F DEBUG : x4 fefeff20800c9b0a x5 fefeff20800c9b0a x6 fefeff20800c9b0a x7 7f7f7f7fff7fff7f 01-05 16:23:23.224 4336 4336 F DEBUG : x8 00000000000000f0 x9 72839d52ae6224ab x10 fffffff0fffffbdf x11 0000000000000000 01-05 16:23:23.224 4336 4336 F DEBUG : x12 0000000000000001 x13 0000000000000000 x14 ffffffffffffffff x15 ff51afd7ed558ccd 01-05 16:23:23.224 4336 4336 F DEBUG : x16 000000795867d8b8 x17 000000795865b710 x18 00000000000f9e32 x19 00000000000000ac 01-05 16:23:23.224 4336 4336 F DEBUG : x20 000000000000108a x21 00000000000000b2 x22 00000000000010eb x23 00000000ffffffff 01-05 16:23:23.224 4336 4336 F DEBUG : x24 0000000000000000 x25 0000000000000001 x26 00000078c4fcd6f0 x27 00000078c4fcd8c0 01-05 16:23:23.224 4336 4336 F DEBUG : x28 00000078c4fcd470 x29 00000078c4fc9e10 01-05 16:23:23.224 4336 4336 F DEBUG : sp 00000078c4fc9d40 lr 000000795860e44c pc 000000795860e46c 01-05 16:23:23.232 4336 4336 F DEBUG : 01-05 16:23:23.232 4336 4336 F DEBUG : backtrace: 01-05 16:23:23.232 4336 4336 F DEBUG : #00 pc 000000000008246c /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: 5812256023147338b8a9538321d4c456) 01-05 16:23:23.232 4336 4336 F DEBUG : #01 pc 00000000000b8124 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libc++_shared.so (BuildId: a9c0aad7747976d255d9ea273f6f4c5003901317) 01-05 16:23:23.233 4336 4336 F DEBUG : #02 pc 00000000000b43d4 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libc++_shared.so (gxx_personality_v0+364) (BuildId: a9c0aad7747976d255d9ea273f6f4c5003901317) 01-05 16:23:23.233 4336 4336 F DEBUG : #03 pc 000000000003aca4 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libjscexecutor.so (BuildId: 9984c1cb185669a215d38fc3546e0e7b8ebbaa8a) 01-05 16:23:23.233 4336 4336 F DEBUG : #04 pc 000000000003afc8 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libjscexecutor.so (_Unwind_RaiseException+252) (BuildId: 9984c1cb185669a215d38fc3546e0e7b8ebbaa8a) 01-05 16:23:23.233 4336 4336 F DEBUG : #05 pc 00000000000b7a78 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libfbjni.so (cxa_throw+112) (BuildId: 8edc347b17ae03442aeaf32376fe2c404c260276) 01-05 16:23:23.233 4336 4336 F DEBUG : #06 pc 0000000000068b94 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libc++_shared.so (std::ndk1::locale::use_facet(std::__ndk1::locale::id&) const+212) (BuildId: a9c0aad7747976d255d9ea273f6f4c5003901317) 01-05 16:23:23.233 4336 4336 F DEBUG : #07 pc 000000000092b560 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #08 pc 0000000000926fbc /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #09 pc 00000000009267b0 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #10 pc 00000000009a1fb0 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #11 pc 00000000009e1f7c /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so (zmqconnect+60) 01-05 16:23:23.233 4336 4336 F DEBUG : #12 pc 0000000000c5c98c /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so (zmq::Socket::connect::hbcee68f1e0e1f76a+144) 01-05 16:23:23.233 4336 4336 F DEBUG : #13 pc 000000000073d990 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #14 pc 0000000000554d28 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #15 pc 00000000005545cc /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #16 pc 0000000000552938 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so ($LT$indy..services..pool..networker..ZMQNetworker$u20$as$u20$indy..services..pool..networker..Networker$GT$::process_event::hf6a0e5976fd223e0+7368) 01-05 16:23:23.233 4336 4336 F DEBUG : #17 pc 00000000003b5b00 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #18 pc 00000000003bc4f0 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #19 pc 0000000000419210 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #20 pc 0000000000411904 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #21 pc 0000000000418958 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #22 pc 00000000006413c8 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #23 pc 000000000052bae4 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #24 pc 00000000011a51e8 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so (rust_maybe_catch_panic+32) 01-05 16:23:23.233 4336 4336 F DEBUG : #25 pc 000000000065a150 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #26 pc 000000000117dddc /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #27 pc 00000000011a44e8 /data/app/com.versiontest-VPGJ2Y-CfSgTxtLEnDa29A==/lib/arm64/libindy.so 01-05 16:23:23.233 4336 4336 F DEBUG : #28 pc 00000000000e372c /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 5812256023147338b8a9538321d4c456) 01-05 16:23:23.233 4336 4336 F DEBUG : #29 pc 0000000000084004 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 5812256023147338b8a9538321d4c456)

jakubkoci commented 3 years ago

I would like just add some more info. There is rn-indy-sdk mentioned in the description, so I just want to clarify it's just React Native wrapper around indy-sdk Android and iOS wrapper in this repo https://github.com/AbsaOSS/rn-indy-sdk.

vinnyhoward commented 3 years ago

I am running into the same issue and getting the same error from Android Studio. I'm currently using "react-native": "0.63.2".

esplinr commented 3 years ago

The issue was introduced with 0.62.0. It works with 0.61.5. @khagesh @vinnyhoward

jakubkoci commented 3 years ago

According to logs, it seems like the problem happens at this line https://github.com/hyperledger/indy-sdk/blob/master/libindy/src/services/pool/networker.rs#L334.

Also worth mentioning that it works on iOS (tested with RN 0.62.0)

Artemkaaas commented 3 years ago

Thanks, @jakubkoci for the report and investigation. You are correct that zmq_connect lead to the crash. 2020-09-11 11:18:36.543 28654-28654/? A/DEBUG: #08 pc 0000000000bcede0 /data/app/za.co.absa.identity-g-kBtLJkIiy5lONScXOHNw==/lib/arm64/libvcx.so (_ZNSt6__ndk124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m+368) 2020-09-11 11:18:36.543 28654-28654/? A/DEBUG: #09 pc 0000000000bca83c /data/app/za.co.absa.identity-g-kBtLJkIiy5lONScXOHNw==/lib/arm64/libvcx.so (_ZNSt6__ndk1lsIcNS_11char_traitsIcEENS_9allocatorIcEEEERNS_13basic_ostreamIT_T0_EES9_RKNS_12basic_stringIS6_S7_T1_EE+368) 2020-09-11 11:18:36.543 28654-28654/? A/DEBUG: #10 pc 0000000000bca030 /data/app/za.co.absa.identity-g-kBtLJkIiy5lONScXOHNw==/lib/arm64/libvcx.so (_ZNK3zmq9address_t9to_stringERNSt6__ndk112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEE+2344) 2020-09-11 11:18:36.543 28654-28654/? A/DEBUG: #11 pc 0000000000c45830 /data/app/za.co.absa.identity-g-kBtLJkIiy5lONScXOHNw==/lib/arm64/libvcx.so (_ZN3zmq13socket_base_t7connectEPKc+9356) 2020-09-11 11:18:36.543 28654-28654/? A/DEBUG: #12 pc 0000000000c857fc /data/app/za.co.absa.identity-g-kBtLJkIiy5lONScXOHNw==/lib/arm64/libvcx.so (zmq_connect+60)

In React Native 0.62.0 have been changed one of system libraries libfb.so -> libfbjni.so: https://github.com/facebook/react-native/commit/9ad5e72b77013083f925108870ea6b17f4711a1d Internallly zmq_connect calls _ZNSt6__ndk124__put_character_sequenceIcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m function which actually leads to zmq_connect crash. For react < 0.62 it was taken from libfb.so but for react >=0.62 is taken from libfbjni.so. Also, they are using NDK of the 21 version. Libindy is build using NDK 20. As I understand @khagesh has already seen a similar crash during some of the past React updates when LIbindy was build using NDK 16 and gnustl. It looks like we need to rebuild Libindy dependencies again.

TimoGlastra commented 3 years ago

I'm curious if there is any update on this? 👀

khagesh commented 3 years ago

@TimoGlastra Sorry, we don't have any fix yet. We are tackling another issue internally. But this issue is definitely a priority for us. We are hoping to get started on this issue very soon. Sorry for not providing exact time.

We also have few of our apps written in react-native. So, this issue is one of the priority for us as well. We will update here once we start working on this issue.

mikaeljan commented 3 years ago

Are there any updates regarding this issue?

JamesKEbert commented 3 years ago

@mikaeljan we have a client implementation that is using RN 0.63.3 currently--although we need to do some additional investigating as to the exact details that has enabled this capability (as we were not the developers that achieved this). This hopefully/likely is something that we can further dig into shortly.

JamesKEbert commented 3 years ago

Have an update here on this--after some digging from @TheTreek and I, we identified that running Android with Hermes enables successful opening of the pool (at least we've tested for React Native v0.63.3 and v0.64.1). Here is an the example project that was used for testing: https://github.com/TheTreek/rn-indy-demo And a branch that we'll be doing a PR to Aries Bifold shortly: https://github.com/Indicio-tech/aries-mobile-agent-react-native/tree/feature/upgradeRN

Interestingly it also works when running in debug mode (using Chrome's engine), which leads me to believe that Hermes is either doing a compile step or causing a side affect of sorts (although I'm not sure as of what). This does make me a little concerned for longer-term resolution, however it will at least if nothing else get us able to use v0.64.1 of React Native.

Another option is utilizing Indy-VDR as a proxy server for ledger operations. I was considering using it as an on-device replacement to switch to for ledger operations, which does help reduce our dependency on Indy SDK, but as far as I know Indy VDR is also unfortunately utilizing ZMQ--which doesn't end up solving this problem.

TimoGlastra commented 3 years ago

Thanks for this @JamesKEbert and @TheTreek! I can confirm this works in RN 0.64.0. Really great work, and thanks for looking into this! :)

TimoGlastra commented 2 years ago

I ran into this issue again in our app. It crashed whenever you opened a pool. After a lot of adding and removing stuff I came to the conclusion that is was because we had updated flipper from 0.75.1 to 0.98.0 in gradle.properties. I'm not sure what the reason is, or if any versions between 0.75.1 and 0.98.0 will work, but I'll stay at 0.75.1 for now :)

Maybe I can save some of you some headaches with this

# Version of flipper SDK to use with React Native 
-FLIPPER_VERSION=0.75.1
+FLIPPER_VERSION=0.98.0 // don't do this
JamesKEbert commented 2 years ago

Yeah, I had found issues in regards to Flipper--in fact this issue was completely solved in an unrelated ZMQ RN project via removal of Flipper: https://github.com/LNP-BP/react_native_demo/issues/1#issuecomment-657206277

jakubkoci commented 2 years ago

I have new findings. Unfortunately, it won't solve anything, but I just want to add it here for information:

App with React Native 0.64.2 also crashes with ZMQ error when you set the following flag in AndroidManifest.xml file:

android:extractNativeLibs="true"

You can find more info about the flag at https://developer.android.com/studio/releases/gradle-plugin#extractNativeLibs. The trick is that this flag was in previous version of Android Gradle plugin set to true by default, they changed it in version 3.6.0, which is used by a higher version of RN (I assume), therefore update of React Native seemed to solve the issue but it actually didn't.

erenakyildiz-code commented 2 years ago

Is there any update on this ?

TimoGlastra commented 2 years ago

@erenakyildiz-code see this comment: https://github.com/hyperledger/indy-sdk/issues/2346#issuecomment-841000640

It works if you enable hermes on Android. It's not a fix per se, but we've all switched to using Hermes

erenakyildiz-code commented 2 years ago

I see, i will post a pr to rn-indy-sdk library to change the example demo project. Thanks for the response.

TimoGlastra commented 2 years ago

rn-indy-sdk has been deprecated in favour of https://github.com/hyperledger/indy-sdk-react-native, but a PR to that repo would be much appreciated!