realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Realm lock threads with two bundle applications

Open gutoglup opened this issue 7 years ago • 14 comments

I have two bundles running simultaneously in the react-native, having the following structure:

  • RCTRootView
    • UIView
      • RCTRootView

When this view structure is applied, realm starts the new thread successfully in the first RCTRootView. When the second thread will start with the second RCTRootView, the code that checks if the thread is finished goes into loops, locking the main thread and blocking the bundle loading.

It has been verified that the code that is causing this problem is in the class: From issue #1065 implementation. RealmReact.mm - 275 until 285 - below:

void _initializeOnJSThread(JSContextRefExtractor jsContextExtractor) {
    // Make sure the previous JS thread is completely finished before continuing.
    static __weak NSThread *s_currentJSThread;
    while (s_currentJSThread && !s_currentJSThread.finished) {
        [NSThread sleepForTimeInterval:0.1];
    }
    s_currentJSThread = [NSThread currentThread];

    // Close all cached Realms from the previous JS thread.
    realm::_impl::RealmCoordinator::clear_all_caches();

    RJSInitializeInContext(jsContextExtractor());
}

Version of Realm and Tooling

  • Realm JS SDK Version: 1.10.0
  • React Nattive: 0.41.2
  • Client OS & Version: Mac OS 10.12.6

gutoglup avatar Aug 15 '17 12:08 gutoglup

@gutoglup Thanks for reporting.

kneth avatar Aug 16 '17 09:08 kneth

Same problem here. Do you know the last version which this problem doesn't occur? This is blocking our development and we can't rollback to versions before 1.9.0 cause we need the backlink feature too. Thanks in advance.

Realm JS SDK Version: 1.10.0
React Native: 0.44.0
Client OS & Version: Mac OS 10.12.4

jpsslink avatar Aug 21 '17 14:08 jpsslink

@gutoglup @jpsslink Currently we support only one instance. We will consider multiple instances as a future enhancement.

kneth avatar Aug 22 '17 12:08 kneth

@kneth, i know that you treated this issue as a future enhancement, but we tested running realm and opening two bundles on Android and this behavior didn't occur, it only happens on iOS.

Was the feature of running more than one instance already implemented, since it works on Android? If yes, couldn't it really be a bug on iOS?

Again, thanks in advance.

jpsslink avatar Aug 23 '17 21:08 jpsslink

@jpsslink the difference in behavior between iOS and Android is due to the way Realm plugs into React Native on those platforms. It's only incidental that using Realm in two or more bundles in the same applications works on Android - it's not something we officially support and test for.

fealebenpae avatar Aug 23 '17 22:08 fealebenpae

Same problem here.

andcosta avatar Aug 24 '17 15:08 andcosta

Same problem.

alexandrelandim avatar Aug 24 '17 17:08 alexandrelandim

@kneth I also want to support this thread. Without it, it's impossible difficult to use realm on my app. We have multiples react native bundle on my app. Many guys that are not creating an app from scratch are on the same scenario.

oximer avatar Aug 24 '17 17:08 oximer

Same problem.

allanalves avatar Aug 25 '17 16:08 allanalves

Any update on this?

saadqbal avatar Jan 08 '19 08:01 saadqbal

Sam problem

linrium avatar Apr 03 '19 10:04 linrium

Any update on this?

Darwin-Ming avatar Aug 28 '20 06:08 Darwin-Ming

Sam problem

HelloZhu avatar Dec 02 '21 07:12 HelloZhu

@gutoglup @jpsslink Currently we support only one instance. We will consider multiple instances as a future enhancement.

Hello, does it now support multiple instances?

HelloZhu avatar Dec 02 '21 07:12 HelloZhu