Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(0.69.10) Android 10 Devices crash with java.lang.RuntimeException: Could not invoke WebSocketModule.connect #16182

Closed
siddarthkay opened this issue Jun 5, 2023 · 29 comments
Assignees

Comments

@siddarthkay
Copy link
Contributor

siddarthkay commented Jun 5, 2023

Bug Report

Android devices API Level 29 with x86_64 CPU Architecture (Android 10) in E2E pipeline have been failing with java.lang.RuntimeException: Could not invoke WebSocketModule.connect
Stack Trace here : https://github.com/status-im/status-mobile/files/11651191/reactupgrade.log

Problem

Relevant part of stack trace is below :


--------- beginning of crash
06-05 10:44:37.000 23608 24782 E AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
06-05 10:44:37.000 23608 24782 E AndroidRuntime: Process: im.status.ethereum.pr, PID: 23608
06-05 10:44:37.000 23608 24782 E AndroidRuntime: java.lang.RuntimeException: Could not invoke 
WebSocketModule.connect
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.facebook.react.bridge.JavaMethodWrapper.
invoke(JavaMethodWrapper.java:383)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at
com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.facebook.react.bridge.queue.
NativeRunnable.run(Native Method)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:900)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:103)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.facebook.react.bridge.queue.
MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:219)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.facebook.react.bridge.queue.
MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at java.lang.Thread.run(Thread.java:929)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.facebook.react.bridge.JavaMethodWrapper.
invoke(JavaMethodWrapper.java:372)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	... 8 more
06-05 10:44:37.000 23608 24782 E AndroidRuntime: Caused by: java.lang.AssertionError: No System TLS:
 java.security.KeyManagementException: java.security.KeyStoreException: BKS not found
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at okhttp3.internal.platform.Platform
.newSslSocketFactory(Platform.kt:171)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at okhttp3.OkHttpClient.<init>(OkHttpClient.kt:238)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at okhttp3.OkHttpClient$Builder.
build(OkHttpClient.kt:1069)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.facebook.react.modules.websocket.
WebSocketModule.connect(WebSocketModule.java:96)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	... 10 more
06-05 10:44:37.000 23608 24782 E AndroidRuntime: Caused by: java.security.KeyManagementException:
java.security.KeyStoreException: BKS not found
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.android.org.conscrypt.SSLParametersImpl.
createDefaultX509KeyManager(SSLParametersImpl.java:539)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.android.org.conscrypt.SSLParametersImpl.
getDefaultX509KeyManager(SSLParametersImpl.java:520)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.android.org.conscrypt.SSLParametersImpl.
<init>(SSLParametersImpl.java:128)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.android.org.conscrypt.OpenSSLContextImpl.
engineInit(OpenSSLContextImpl.java:111)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at javax.net.ssl.SSLContext.init(SSLContext.java:326)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at okhttp3.internal.platform.Platform
.newSslSocketFactory(Platform.kt:168)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	... 13 more
06-05 10:44:37.000 23608 24782 E AndroidRuntime: Caused by: java.security.KeyStoreException: BKS not found
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at java.security.KeyStore.getInstance(KeyStore.java:890)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.android.org.conscrypt.KeyManagerFactoryImpl
.engineInit(KeyManagerFactoryImpl.java:63)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at javax.net.ssl.KeyManagerFactory.
init(KeyManagerFactory.java:272)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at com.android.org.conscrypt.SSLParametersImpl.
createDefaultX509KeyManager(SSLParametersImpl.java:528)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	... 18 more
06-05 10:44:37.000 23608 24782 E AndroidRuntime: Caused by: java.security.NoSuchAlgorithmException: 
BKS KeyStore not available
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at sun.security.jca.GetInstance.
getInstance(GetInstance.java:159)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at java.security.Security.getImpl(Security.java:628)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	at java.security.KeyStore.getInstance(KeyStore.java:887)
06-05 10:44:37.000 23608 24782 E AndroidRuntime: 	... 21 more


Expected behaviour

Don't crash :)

Actual behaviour

crash :(

Additional Information

  • Status version: nightly
  • Operating System: Android 10

reported here : #16016 (comment)

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 5, 2023

part of our error is similar to this age old issue : #10770

  • Caused by: java.lang.AssertionError: No System TLS: java.security.KeyManagementException: java.security.KeyStoreException: BKS not found
  • Caused by: java.security.KeyStoreException: BKS not found
  • Caused by: java.security.NoSuchAlgorithmException: BKS KeyStore not available

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 5, 2023

After I set up an emulator with arm64 Architecture and API 29 (Android 10) this is the first thing I see on running a Debug build.

Screenshot 2023-06-05 at 10 59 45 PM

But, I haven't been able to reproduce this ever since.

note : This is not the same error which appears on E2E.

@siddarthkay
Copy link
Contributor Author

I tried to reproduce our error on an emulator with x86_64 architecture API Level 29 (Android 10)
And I wasn't able to reproduce it with a debug build of the app
ref :

debug-x86-API29

@siddarthkay
Copy link
Contributor Author

I tried to reproduce our error on an emulator with x86_64 architecture API Level 29 (Android 10)
And I wasn't able to reproduce it with a PR build of the app
ref :

PR-x86_64-Android10

@siddarthkay
Copy link
Contributor Author

At this point I even considered trying x86 architecture instead of x86_64 but was not able to reproduce the error

Debug Build Screenshot below :
x86-debug-api29

PR Build Screenshot below :
x86-PR-API29

@siddarthkay
Copy link
Contributor Author

This error seems to not be reproducible for me locally.
What can we do in this case? @churik @yevh-berdnyk @VladimrLitvinenko

just a thought : Maybe if this still persists on E2E we can consider upgrading either Android API Level from 29 to 31 or try with different CPU architecture like arm64 (which are a lot faster at everything).

cc: @cammellos @jakubgs

@yevh-berdnyk
Copy link
Contributor

This error seems to not be reproducible for me locally. What can we do in this case? @churik @yevh-berdnyk @VladimrLitvinenko

just a thought : Maybe if this still persists on E2E we can consider upgrading either Android API Level from 29 to 31 or try with different CPU architecture like arm64 (which are a lot faster at everything).

cc: @cammellos @jakubgs

Hi @siddarthkay,
I've just tried on my local emulator (Pixel 3a XL API29, x86) with the latest apk from #16016 and unfortunately it's still reproducible.
And regarding arm64 - SauceLabs introduce only x86_64 emulators, arm64 can be used on real devices only which we don't use for testing now.

@KassUA
Copy link

KassUA commented Jun 8, 2023

Hi! I am also reproducing the crash on my physical device Redmi Note 8 Pro, Android 10 using latest build (#35) from this PR #16016

For me, crash occurs only at first opening of fresh installed app and not every time. Approximately in 1 of 3 tries.

XRecorder_08062023_125017.mp4

@qoqobolo
Copy link
Contributor

qoqobolo commented Jun 8, 2023

Hey @siddarthkay, still can reproduce on the real Android 10 device - Huawei P40 lite
The error occurs about 1 out of 5-7 times.

video_2023-06-08_11-15-15.mp4

@pavloburykh
Copy link
Contributor

@siddarthkay it turned out that it is reproducible not only on Android 10. I have just cought the crash on my physical Android 12, Samsung Galaxy A52.

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 8, 2023

Thanks @pavloburykh @yevh-berdnyk @KassUA @qoqobolo !

Okay then it seems like its easily reproducible on a lot of your real devices and its not consistent, some say 1 in 5 times and 1 in 3 times.
I'll try reproducing on my device and will post my investigations here.

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 8, 2023

Once again looking at the stack trace above it seems like the error is thrown by the OkHttpClient library.

And most likely the root cause is this guy right here : https://square.github.io/okhttp/changelogs/changelog_4x/#version-4100 -> this link does mention a fix for Android 10 which makes it a bit suspicious :)

@siddarthkay
Copy link
Contributor Author

Finally managed to get my hands on an android 10 device and i can reproduce this error on first try.
Investigating further...

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 11, 2023

The crash originates here : android/app/src/main/java/im/status/ethereum/StatusOkHttpClientFactory.java

The crash happens mostly the 1st time the app is installed and then it never happens.
When I remove and reinstall the app the crash happens and sometimes it's not the 1st time, its maybe 3rd or 5th time.

The error is most likely thrown here : kotlin/okhttp3/internal/platform/Platform.kt

@siddarthkay
Copy link
Contributor Author

I think I fixed this issue by making sure our OkHttp Version matches React Native's OkHttp Version.
After bumping OkHttp to 4.9.2 I wasn't able to reproduce the crash on my Android 10 device.

Running E2E will tell if it worked or not 🤞🏻

@siddarthkay
Copy link
Contributor Author

E2E still brutally fails : 0% tests passed :

I'll try recreating it on my Android 10 device again 🥲
Meanwhile can any of you still recreate the crash on your devices? @qoqobolo @pavloburykh @yevh-berdnyk @KassUA ?

@pavloburykh
Copy link
Contributor

@siddarthkay hello! I was not able to reproduce "Could not invoke WebSocketModule.connect" crash on my Android 12, Samsung Galaxy A52. But currently I am facing another crash which appears during generating keys. After app reopening it is possible to login newly created account. See details below.

photo_2023-06-12 11 39 15

telegram-cloud-document-2-5202210366263670185.mp4

The same issue happens to e2e tests which causes failing.

https://app.eu-central-1.saucelabs.com/tests/c1c898960ad047d986c9588619bab7cc?auth=2574580cb4e83edc55dcb92380e76ec1#28

Here is logcat from recent e2e session
logcat (5).log

@pavloburykh
Copy link
Contributor

pavloburykh commented Jun 12, 2023

Although I also see that some e2e are still failing with "Could not invoke WebSocketModule.connect" crash. See example below:

https://app.eu-central-1.saucelabs.com/tests/126b1119fa854249978053dfa8feb799?auth=16cb876709e72699df42b8203d6a4f19#2

logcat (6).log

@siddarthkay
Copy link
Contributor Author

I also that some e2e are still failing with "Could not invoke WebSocketModule.connect" crash.

yes, I saw that too, and this is my primary worry for now :)

@siddarthkay
Copy link
Contributor Author

@pavloburykh : the error after the keys seem to be a new one and I will try to tackle that one in a separate github issue

@qoqobolo
Copy link
Contributor

Meanwhile can any of you still recreate the crash on your devices? @qoqobolo @pavloburykh @yevh-berdnyk @KassUA ?

Hi @siddarthkay, just checked on my Huawei P40 Lite, Android 10, and for me it's the same as for @pavloburykh in the comment

On the first try I got this error

Screenshot 2023-06-12 at 11 44 19

@siddarthkay
Copy link
Contributor Author

Hi @qoqobolo and @pavloburykh : Thanks for testing, I'll focus on fixing that bug then, meanwhile what are your thoughts on this bug :)

@pavloburykh
Copy link
Contributor

Hi @qoqobolo and @pavloburykh : Thanks for testing, I'll focus on fixing that bug then, meanwhile what are your thoughts on this bug :)

"Could not invoke WebSocketModule.connect" is still blocker for our e2e tests. Let's ask @yevh-berdnyk what she thinks about that and if there any workaround to prevent e2e from failure in case of this crash.

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 12, 2023

@pavloburykh : I fixed the issue Cannot read property toGestureArray of null and after running E2E I do not see our Could not invoke WebSocketModule.connect crash as well, there are new errors so yay.

E2E result : #16016 (comment)

Can you check once?

@pavloburykh
Copy link
Contributor

Can you check once?

Thanx @siddarthkay I will look at it tomorrow

@pavloburykh
Copy link
Contributor

@siddarthkay I am re-running e2e. Will see the results.

@pavloburykh
Copy link
Contributor

pavloburykh commented Jun 13, 2023

@siddarthkay so far, most of the failed e2e are known ones and not related to the PR. Crashes have not been caught neither by e2e nor by my physical device. @VladimrLitvinenko will proceed with testing the PR as he has been kinda blocked from proper testing because of crashes. He will provide an update in PR comments as soon as he finishes. Thank you!

@siddarthkay
Copy link
Contributor Author

siddarthkay commented Jun 13, 2023

Fixed with bumping okhttp-tls in android/app/build.gradle

-    implementation "com.squareup.okhttp3:okhttp-tls:4.9.1"
+    implementation "com.squareup.okhttp3:okhttp-tls:4.9.2"

Reason : to match our okhttp lib with what react native uses, since we override the httpclient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants