Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-322

Node.js doesn't terminate if Realm.Sync.Adapter is used to open a Realm

    • Type: Icon: Bug Bug
    • Resolution: Gone away
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None

      <!---

      Questions: If you have questions about HOW TO use Realm, please ask on
      StackOverflow: http://stackoverflow.com/questions/ask?tags=realm
      We monitor the realm tag.

      Feature Request: Just fill in the first two sections below.

      Bugs: To help you as fast as possible with an issue please describe your issue
      and the steps you have taken to reproduce it in as much detail as possible.

      -->

      Goals

      I am using the Realm.Sync.Adapter API and I am trying to get the Node.js process to finish when I am done using the adapter API. However, if I use the adapter to open any Realm, the Node.js process never finishes executing.

      Expected Results

      This is my TypeScript code:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      import * as Realm from 'realm';
      
      const schemas: Realm.ObjectSchema[] = [
          {
            name: 'TestObj',
            primaryKey: 'pk',
            properties: {
              pk: 'string',
              a: 'string',
              b: 'int',
              c: 'bool',
            }
          }
        ]
      
      let adapter: Realm.Sync.Adapter;
      Realm.Sync.User.login(
        'https://my-realm-cloud-instance.us1.cloud.realm.io', 
        Realm.Sync.Credentials.usernamePassword('my_username', 'my_password')
      ).then(user => {
        adapter = new Realm.Sync.Adapter(
          'adapterData',
          'realms://my-realm-cloud-instance.us1.cloud.realm.io',
          user,
          `.*`,
          (blah: string) => {console.log(blah)}
        )
      
        // If I comment out these two lines of code, then the process will terminate
        const realm = adapter.realmAtPath('/localTestData', schemas)
        realm.close()
      
        adapter.close()
        user.logout()
      
        return;
      }).catch(err => {
        console.log(err)
      })
      

      I would expect the above compiled Node.js program to finish to completion and terminate.

      Actual Results

      <!--- What happened instead? -->
      <!--- e.g. the stack trace of a crash -->

      Instead of terminating, the above program hangs indefinitely. If I sample the process, one of the threads seems to be stuck in realm::util::network::Service::Impl::run() in realm.node.

         2657 Thread_2764463
          + 2657 thread_start  (in libsystem_pthread.dylib) + 13  [0x7fff74c8d40d]
          +   2657 _pthread_start  (in libsystem_pthread.dylib) + 66  [0x7fff74c91249]
          +     2657 _pthread_body  (in libsystem_pthread.dylib) + 126  [0x7fff74c8e2eb]
          +       2657 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, realm::_impl::SyncClient::SyncClient(std::__1::unique_ptr<realm::util::Logger, std::__1::default_delete<realm::util::Logger> >, realm::sync::Client::ReconnectMode, bool, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)::'lambda'()> >(void*)  (in realm.node) + 45  [0x10511965d]
          +         2657 realm::util::network::Service::Impl::run()  (in realm.node) + 742  [0x105176446]
          +           2657 realm::util::network::Service::IoReactor::wait_and_advance(std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >, bool&, realm::util::network::Service::OperQueue<realm::util::network::Service::AsyncOper>&)  (in realm.node) + 34  [0x105175a92]
          +             2657 realm::util::network::Service::IoReactor::wait_and_activate(std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >, std::__1::chrono::time_point<std::__1::chrono::steady_clock, std::__1::chrono::duration<long long, std::__1::ratio<1l, 1000000000l> > >)  (in realm.node) + 89  [0x105175529]
          +               2657 kevent  (in libsystem_kernel.dylib) + 10  [0x7fff74bdb78e]
          2657 Thread_2764464
            2657 start_wqthread  (in libsystem_pthread.dylib) + 13  [0x7fff74c8d3fd]
              2657 _pthread_wqthread  (in libsystem_pthread.dylib) + 634  [0x7fff74c8d6e6]
                2657 __workq_kernreturn  (in libsystem_kernel.dylib) + 10  [0x7fff74bd6bfe]
      

      Steps to Reproduce

      <!--- What are steps we can follow to reproduce this issue? -->

      Compile the above code sample with this tsconfig.json:

      {
        "compilerOptions": {
          "target": "es6",
          "module": "commonjs", 
          "moduleResolution": "node"
        }
      }
      

      and run the program. It will not terminate, unless the following two lines are commented out:

      Unable to find source-code formatter for language: typescript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
        const realm = adapter.realmAtPath('/localTestData', schemas)
        realm.close()
      

      Code Sample

      <!---
      Please provide a code sample or test case that highlights the issue.
      If relevant, include your model definitions.
      For larger code samples, links to external gists/repositories are preferred.
      Full projects that we can compile and run ourselves are ideal!
      -->

      Version of Realm and Tooling

      • Realm JS SDK Version: 2.29.2
      • Node or React Native: Node v10.15.3
      • Client OS & Version: Darwin REDACTED 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64 (13-inch Macbook Pro 2017, macOS 10.14.4)

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: