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

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

Closed
adamchel opened this issue Sep 12, 2019 · 1 comment
Closed

Comments

@adamchel
Copy link

adamchel commented Sep 12, 2019

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:

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

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

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:

  const realm = adapter.realmAtPath('/localTestData', schemas)
  realm.close()

Code Sample

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)
@sync-by-unito
Copy link

sync-by-unito bot commented Nov 18, 2021

➤ Brian Munkholm commented:

Adapter API removed so no longer relevant.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants