realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.79k stars 575 forks source link

Realm Assertion Failed #520

Closed saeho closed 8 years ago

saeho commented 8 years ago

Getting this since upgrading to latest version of Realm and React Native 0.28.

It happens when refreshing the app. And this error prevents the app from refreshing, forever stuck in a white screen.

Assertion failed: (signature), function RealmReactGetJSGlobalContextForExecutor, file /..../node_modules/realm/react-native/ios/RealmReact/RealmReact.mm, line 59.

saeho commented 8 years ago

I should also mention that this only happens in the real phone. Simulator seems to have no problem refreshing.

saeho commented 8 years ago

Closing because I cannot reproduce any more. I think upgrading to latest Realm fixed it. I think my build wasn't using the latest version when the error happened again.

jerson commented 8 years ago

i have the same problem in a real device

I reproduce with codePush for restart app, using this line, and sometimes crash

         codePush.restartApp(false);
jerson commented 8 years ago

here is the trace

#4  0x0000000100306104 in ::RealmReactGetJSGlobalContextForExecutor(id, bool) at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/realm/react-native/ios/RealmReact/RealmReact.mm:59
#5  0x0000000100308c9c in ::__24-[RealmReact setBridge:]_block_invoke() at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/realm/react-native/ios/RealmReact/RealmReact.mm:305
#6  0x000000010021ed3c in ::-[RCTJSCExecutor executeBlockOnJavaScriptQueue:](dispatch_block_t) at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/react-native/React/Executors/RCTJSCExecutor.mm:697
#7  0x00000001882ed024 in __NSThreadPerformPerform ()
#11 0x0000000187755764 in CFRunLoopRunSpecific ()
#12 0x00000001002175b8 in ::+[RCTJSCExecutor runRunLoopThread]() at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/react-native/React/Executors/RCTJSCExecutor.mm:260
heracek commented 8 years ago

@saeho please reopen this issue, I've got same problem with v0.14.1 on real iOS devices in production.

Problem seems to be on this line RealmReact.mm:56:

NSMethodSignature *signature = [RCTJavaScriptContext instanceMethodSignatureForSelector:@selector(initWithJSContext:)];

Because method initWithJSContext: no longer exists asertion fails all the time and it crashes the app.

The method was replaced by initWithJSContext:onThread: (I'm using React Native v0.28.0). It seems that even RCTJavaScriptContext requires thread as an additional argument (there is no initWithJSContext:, it was replaced by initWithJSContext:onThread:).

I can produce Pull Request, but I don't undestand code of RealmReactGetJSGlobalContextForExecutor in depth. For example:

alazier commented 8 years ago

@heracek pull requests are welcome, although I hope to get this issue resolved asap so that we are compatible with the latest react-native versions.

I don't recall the that the context was previously created and set when calling - (RCTJavaScriptContext *)context so we can start using this moving forward. Before calling this we do need to ensure that the _javaScriptThread has been set.

A context is not needed when using RCTWebSocketExecutor as this executor simply forwards all requests to the debug server rather than processing them locally.

alazier commented 8 years ago

@heracek @jerson do you see this issue with RN v0.29.0 as well? I am not hitting the code path to trigger this bug with the latest version as at the time RealmReactGetJSGlobalContextForExecutor has been called the context has already been populated.

jerson commented 8 years ago

@alazier I tested in RN v0.29.0 and v0.30.0rc

alazier commented 8 years ago

@jerson @heracek I made a pr #523 in attempt to fix this. Unfortunately I am still unable to reproduce the issue - I tried creating a fresh project with the latest RN version and ran on simulator and device but have been unable to trigger the offending code path. If you are able to test this out or to provide a sample project or instructions to reproduce the crash it would be extremely helpful.

jerson commented 8 years ago

@alazier , I create a sample project for test this error

https://github.com/jerson/realm-example-error and iPA https://github.com/jerson/realm-example-error/releases

sometimes when i press Reload App , crash, but not allways.

but on my project still crash with you pull request, this is the trace

#0  0x00000001001f7f58 in ::-[RCTJSCExecutor context]() at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/react-native/React/Executors/RCTJSCExecutor.mm:303
#1  0x00000001002e6128 in ::RealmReactGetJSGlobalContextForExecutor(id, bool) at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/realm/react-native/ios/RealmReact/RealmReact.mm:63
#2  0x00000001002e8cd4 in ::__24-[RealmReact setBridge:]_block_invoke() at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/realm/react-native/ios/RealmReact/RealmReact.mm:307
#3  0x00000001001fed7c in ::-[RCTJSCExecutor executeBlockOnJavaScriptQueue:](dispatch_block_t) at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/react-native/React/Executors/RCTJSCExecutor.mm:697
#4  0x00000001882ed024 in __NSThreadPerformPerform ()
#8  0x0000000187755764 in CFRunLoopRunSpecific ()
#9  0x00000001001f75f8 in ::+[RCTJSCExecutor runRunLoopThread]() at /Users/gerson/Proyectos/React/SetbeatNative/node_modules/react-native/React/Executors/RCTJSCExecutor.mm:260

the error is com.facebook.react.Javascript(24): EXC_BAD_ACCESS(code=1,address=0x88)

//cc @heracek

heracek commented 8 years ago

Hi, I agree with @jerson. This bug happanes only sometimes (for us it ~2% of users). I think it's related to sometimes one thread being faster then other.

I've posted comment on for #523 with commit suggesting some cahnges.

alazier commented 8 years ago

@jerson - I just pushed a commit that will hopefully resolve this other crash you have run into. Please let me know if this works. If so we will cut a release with these changes.

alazier commented 8 years ago

@jerson @heracek or anyone else that can reproduce this crash: I pushed an rc to npm 0.14.2-rc which should hopefully fix this. Please give it a try and let me know how it goes.

jerson commented 8 years ago

@alazier I tested it and it works, thank you very much now everything is fine 👍