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

crash on iOS 11 #88

Closed
xwartz opened this issue Jul 29, 2020 · 9 comments
Closed

crash on iOS 11 #88

xwartz opened this issue Jul 29, 2020 · 9 comments

Comments

@xwartz
Copy link

xwartz commented Jul 29, 2020

We have Polkadot.js integrated in react-native, but it crashes under iOS 11.

It should be that iOS 11 isn't compatible with wasm. Can we don't use wasm? Or is there a way to make it compatible?

Here is the log:

Crashed: com.facebook.react.JavaScript
0  JavaScriptCore                 0x18bee82e4 JSC::ExecutableAllocator::allocate(unsigned long, void*, JSC::JITCompilationEffort) + 644
1  JavaScriptCore                 0x18bee82e4 JSC::ExecutableAllocator::allocate(unsigned long, void*, JSC::JITCompilationEffort) + 644
2  JavaScriptCore                 0x18c1501dc JSC::LinkBuffer::allocate(JSC::MacroAssembler&, void*, JSC::JITCompilationEffort) + 256
3  JavaScriptCore                 0x18c14f8b4 void JSC::LinkBuffer::copyCompactAndLinkCode<unsigned int>(JSC::MacroAssembler&, void*, JSC::JITCompilationEffort) + 60
4  JavaScriptCore                 0x18c14f7c4 JSC::LinkBuffer::linkCode(JSC::MacroAssembler&, void*, JSC::JITCompilationEffort) + 56
5  JavaScriptCore                 0x18c3208e4 JSC::Wasm::throwExceptionFromWasmThunkGenerator(WTF::AbstractLocker const&) + 764
6  JavaScriptCore                 0x18c320e48 JSC::Wasm::Thunks::stub(WTF::AbstractLocker const&, JSC::MacroAssemblerCodeRef (*)(WTF::AbstractLocker const&)) + 120
7  JavaScriptCore                 0x18c321210 JSC::Wasm::Thunks::stub(JSC::MacroAssemblerCodeRef (*)(WTF::AbstractLocker const&)) + 92
8  JavaScriptCore                 0x18c308b14 JSC::Wasm::Memory::create(JSC::VM&, JSC::Wasm::PageCount, JSC::Wasm::PageCount) + 96
9  JavaScriptCore                 0x18c119540 JSC::JSWebAssemblyInstance::create(JSC::VM&, JSC::ExecState*, JSC::JSWebAssemblyModule*, JSC::JSObject*, JSC::Structure*) + 3020
10 JavaScriptCore                 0x18c342aec JSC::instantiate(JSC::VM&, JSC::ExecState*, JSC::JSPromiseDeferred*, JSC::JSWebAssemblyModule*, JSC::JSObject*, JSC::Resolve) + 116
11 JavaScriptCore                 0x18c2438ac JSC::PromiseDeferredTimer::doWork() + 524
12 JavaScriptCore                 0x18c0d3d70 JSC::JSRunLoopTimer::timerDidFireCallback(__CFRunLoopTimer*, void*) + 76
13 CoreFoundation                 0x184fc3dc0 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28
14 CoreFoundation                 0x184fc3ae4 __CFRunLoopDoTimer + 864
15 CoreFoundation                 0x184fc32e4 __CFRunLoopDoTimers + 248
16 CoreFoundation                 0x184fc0ecc __CFRunLoopRun + 1928
17 CoreFoundation                 0x184ee0c58 CFRunLoopRunSpecific + 436
18 React                          0x102655b2c +[RCTCxxBridge runRunLoop] + 264
19 Foundation                     0x185a170f4 __NSThread__start__ + 996
20 libsystem_pthread.dylib        0x184c442b4 _pthread_body + 308
21 libsystem_pthread.dylib        0x184c44180 _pthread_body + 310
22 libsystem_pthread.dylib        0x184c42b74 thread_start + 4
@jacogr jacogr transferred this issue from polkadot-js/api Jul 29, 2020
@jacogr
Copy link
Member

jacogr commented Jul 29, 2020

Under RN asm.js is used as a fallback - https://github.com/polkadot-js/wasm/blob/master/packages/wasm-crypto/package.json#L17-L19

As long as the builder does not override the bundler the fallback should be in place.

Some functionality like sr25519 (the Substrate-suggested crypto) is only available in WASM.

@xwartz
Copy link
Author

xwartz commented Jul 29, 2020

But it doesn't seem to work, because it still crashes.

@xwartz
Copy link
Author

xwartz commented Jul 29, 2020

Crashes only on iOS 11, not on other versions.

similar error:
https://marc.info/?l=webkit-unassigned&m=151056701701087&w=2
https://bugs.webkit.org/show_bug.cgi?id=181781

@xwartz
Copy link
Author

xwartz commented Jul 29, 2020

Is it possible that the crash occurred while processing a fallback??

https://github.com/polkadot-js/wasm/blob/44c62a7b3d/packages/wasm-crypto/src/js/wasm_promise.js#L13

@xwartz
Copy link
Author

xwartz commented Jul 29, 2020

I'm guessing that since WebAssembly is supported on JSC iOS Device, so it didn't fallback to ams.js.
But the iOS 11 has a bug, it isn't fully compatible with wasm, then the crash occurred.

@jacogr
Copy link
Member

jacogr commented Jul 29, 2020

I don't have a quick solution atm - it is possible to override that file completely to only use the asm.js version (so it never does a fallback).

I do actually plan on doing something simmilar in a future version (WIP), but I'm actually guessing here it may still fail if WebAssembly is available.

@xwartz
Copy link
Author

xwartz commented Jul 30, 2020

I tested that it won't crash on iOS 11 if direct fallback to ams.js. So my guess above is correct.

@jacogr
Copy link
Member

jacogr commented Nov 3, 2020

From 2.0 onwards (in beta as of now), you can do the following to ensure it always takes the asm.js path on RN. In package.json -

"react-native": {
  "@polkadot/wasm-crypto/wasm/bytes": "@polkadot/wasm-crypto/wasm/bytes-empty"
}

This basically instructs the init path to supply empty WASM bytes, which will skip that path and go into fallback immediately. By default it, regardless of platform, it will still try WASM and if it fails, will fallback to asm (if available), that doesn't change. With the above you can force it to only use asm.js in all cases.

(The package already applies an wasm/asm-empty -> wasm/asm mapping on RN, as linked above - however that can be applied on other plaforms as well should you wish to use the asm.js version as fallback, or to skip WASM completely as above)

@jacogr jacogr closed this as completed Nov 3, 2020
@polkadot-js-bot
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue if you think you have a related problem or query.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators May 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants