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

Open handles/threads in 12.0 #6096

Closed
sergeysedoy97 opened this issue Aug 23, 2023 · 13 comments
Closed

Open handles/threads in 12.0 #6096

sergeysedoy97 opened this issue Aug 23, 2023 · 13 comments

Comments

@sergeysedoy97
Copy link

How frequently does the bug occur?

Always

Description

wtfnode node_modules/realm/dist/bundle.node.js
^C
[WTF Node?] open handles:
- File descriptors: (note: stdio always exists)
  - fd 1 (tty) (stdio)
  - fd 0 (tty)
  - fd 2 (tty) (stdio)

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

node node_modules/realm/dist/bundle.node.js is always waiting for input

Version

12

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Any

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

@kneth
Copy link
Member

kneth commented Aug 24, 2023

Is your issue that your process doesn't terminate? If so, can you explain about your use case in more details?

File descriptor 0, 1, and 2 will be open for any process on a POSIX compliant operating system.

@sync-by-unito sync-by-unito bot added the Waiting-For-Reporter Waiting for more information from the reporter before we can proceed label Aug 24, 2023
@sergeysedoy97
Copy link
Author

Is your issue that your process doesn't terminate? If so, can you explain about your use case in more details?

File descriptor 0, 1, and 2 will be open for any process on a POSIX compliant operating system.

Yes, process doesn't terminate. The problem is that unit testing is impossible in such case.

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Aug 24, 2023
@kneth
Copy link
Member

kneth commented Aug 25, 2023

It sounds like you are not using React Native but you might find https://www.mongodb.com/docs/realm/sdk/react-native/test-and-debug/testing/ useful. If you are using Jest as test harness, we have seen similar issues in the past.

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Aug 25, 2023
@sergeysedoy97
Copy link
Author

It sounds like you are not using React Native but you might find https://www.mongodb.com/docs/realm/sdk/react-native/test-and-debug/testing/ useful. If you are using Jest as test harness, we have seen similar issues in the past.

We call close method, it works fine in Realm 11, but how close can help if it's enought to just do an import of Realm package w/o any initialization of database so JS file will never end. We use Node.js SDK

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Aug 28, 2023
@sergeysedoy97
Copy link
Author

sergeysedoy97 commented Aug 28, 2023

>596 const _native_Results_get_type = nativeModule.Results_get_type;
 597 let Results$1 = class Results {
 598   constructor(ptr) {
debug> n
debug> There was an internal error in Node.js. Please report this bug.
read ECONNRESET
Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17

Any class expression causes a problem with debbuger

@sergeysedoy97 sergeysedoy97 changed the title Open handles in 12.0 Open handles/threads in 12.0 Aug 28, 2023
@kneth
Copy link
Member

kneth commented Aug 31, 2023

We should use some context of what you are trying to do. Can you provide instructions on how to reproduce it?

@sync-by-unito sync-by-unito bot added Waiting-For-Reporter Waiting for more information from the reporter before we can proceed and removed Needs-Attention Reporter has responded. Review comment. labels Aug 31, 2023
@sergeysedoy97
Copy link
Author

We should use some context of what you are trying to do. Can you provide instructions on how to reproduce it?

PowerShell 7.3.6
PS C:\Users\root\Desktop\realm-12> yarn init
yarn init v1.22.19
question name (realm-12):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
Done in 4.71s.
PS C:\Users\root\Desktop\realm-12> yarn add realm
yarn add v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 44 new dependencies.
info Direct dependencies
└─ realm@12.1.0
info All dependencies
├─ base64-js@1.5.1
├─ bl@4.1.0
├─ bson@4.7.2
├─ buffer@5.7.1
├─ chownr@1.1.4
├─ debug@4.3.4
├─ decompress-response@6.0.0
├─ deep-extend@0.6.0
├─ detect-libc@2.0.2
├─ end-of-stream@1.4.4
├─ expand-template@2.0.3
├─ fs-constants@1.0.0
├─ github-from-package@0.0.0
├─ ieee754@1.2.1
├─ ini@1.3.8
├─ lru-cache@6.0.0
├─ mimic-response@3.1.0
├─ minimist@1.2.8
├─ mkdirp-classic@0.5.3
├─ ms@2.1.2
├─ napi-build-utils@1.0.2
├─ node-abi@3.47.0
├─ node-fetch@2.7.0
├─ node-machine-id@1.1.12
├─ once@1.4.0
├─ prebuild-install@7.1.1
├─ rc@1.2.8
├─ readable-stream@3.6.2
├─ realm@12.1.0
├─ safe-buffer@5.2.1
├─ semver@7.5.4
├─ simple-concat@1.0.1
├─ simple-get@4.0.1
├─ string_decoder@1.3.0
├─ strip-json-comments@2.0.1
├─ tar-fs@2.1.1
├─ tar-stream@2.2.0
├─ tr46@0.0.3
├─ tunnel-agent@0.6.0
├─ util-deprecate@1.0.2
├─ webidl-conversions@3.0.1
├─ whatwg-url@5.0.0
├─ wrappy@1.0.2
└─ yallist@4.0.0
Done in 3.71s.
PS C:\Users\root\Desktop\realm-12> node -e 'console.log("last line of code");'
last line of code
PS C:\Users\root\Desktop\realm-12> node -e 'require("realm");console.log("last line of code");'
last line of code
<app isn't terminated>

Since Realm 12 we need to call process.exit to terminate app

@github-actions github-actions bot added Needs-Attention Reporter has responded. Review comment. and removed Waiting-For-Reporter Waiting for more information from the reporter before we can proceed labels Sep 6, 2023
@sergeysedoy97
Copy link
Author

Previously,

PS C:\Users\root\Desktop\realm-11> yarn init
yarn init v1.22.19
question name (realm-11):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
Done in 2.05s.
PS C:\Users\root\Desktop\realm-11> yarn add realm@11
yarn add v1.22.19
info No lockfile found.
[1/4] Resolving packages...
warning realm > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
warning realm > request > har-validator@5.1.5: this library is no longer supported
warning realm > request > uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 135 new dependencies.
info Direct dependencies
└─ realm@11.10.2
info All dependencies
├─ @realm/network-transport@0.7.2
├─ abort-controller@3.0.0
├─ ajv@6.12.6
├─ array-back@3.1.0
├─ asap@2.0.6
├─ asn1@0.2.6
├─ asynckit@0.4.0
├─ aws-sign2@0.7.0
├─ aws4@1.12.0
├─ base64-js@1.5.1
├─ bcrypt-pbkdf@1.0.2
├─ bindings@1.5.0
├─ bl@4.1.0
├─ bson@4.4.1
├─ buffer-from@1.1.2
├─ buffer@5.7.1
├─ call-bind@1.0.2
├─ chownr@2.0.0
├─ combined-stream@1.0.8
├─ command-line-args@5.2.1
├─ concat-stream@1.6.2
├─ core-util-is@1.0.3
├─ dashdash@1.14.1
├─ data-uri-to-buffer@4.0.1
├─ decompress-response@6.0.0
├─ deep-extend@0.6.0
├─ deepmerge@2.1.0
├─ delayed-stream@1.0.0
├─ detect-libc@2.0.2
├─ ecc-jsbn@0.1.2
├─ end-of-stream@1.4.4
├─ event-target-shim@5.0.1
├─ expand-template@2.0.3
├─ extend@3.0.2
├─ extsprintf@1.3.0
├─ fast-deep-equal@3.1.3
├─ fast-json-stable-stringify@2.1.0
├─ fetch-blob@3.2.0
├─ file-uri-to-path@1.0.0
├─ find-replace@3.0.0
├─ forever-agent@0.6.1
├─ form-data@2.3.3
├─ formdata-polyfill@4.0.10
├─ fs-constants@1.0.0
├─ fs-extra@4.0.3
├─ fs-minipass@2.1.0
├─ getpass@0.1.7
├─ github-from-package@0.0.0
├─ graceful-fs@4.2.11
├─ har-schema@2.0.0
├─ har-validator@5.1.5
├─ has-proto@1.0.1
├─ has-symbols@1.0.3
├─ has@1.0.3
├─ http-basic@2.5.1
├─ http-response-object@1.1.0
├─ http-signature@1.2.0
├─ ieee754@1.2.1
├─ inherits@2.0.4
├─ ini@1.3.8
├─ is-typedarray@1.0.0
├─ isarray@1.0.0
├─ isstream@0.1.2
├─ js-tokens@4.0.0
├─ json-schema-traverse@0.4.1
├─ json-schema@0.4.0
├─ json-stringify-safe@5.0.1
├─ jsonfile@4.0.0
├─ jsprim@1.4.2
├─ lodash.camelcase@4.3.0
├─ loose-envify@1.4.0
├─ lru-cache@6.0.0
├─ mime-db@1.52.0
├─ mime-types@2.1.35
├─ mimic-response@3.1.0
├─ minimist@1.2.8
├─ minizlib@2.1.2
├─ mkdirp-classic@0.5.3
├─ mkdirp@1.0.4
├─ napi-build-utils@1.0.2
├─ node-abi@3.47.0
├─ node-addon-api@4.2.0
├─ node-domexception@1.0.0
├─ node-fetch@3.3.2
├─ node-machine-id@1.1.12
├─ oauth-sign@0.9.0
├─ object-assign@4.1.1
├─ object-inspect@1.12.3
├─ once@1.4.0
├─ performance-now@2.1.0
├─ prebuild-install@7.1.1
├─ process-nextick-args@2.0.1
├─ progress@2.0.3
├─ promise@7.3.1
├─ prop-types@15.8.1
├─ psl@1.9.0
├─ punycode@2.3.0
├─ qs@6.5.3
├─ querystringify@2.2.0
├─ rc@1.2.8
├─ react-is@16.13.1
├─ readable-stream@3.6.2
├─ realm@11.10.2
├─ request@2.88.2
├─ requires-port@1.0.0
├─ safe-buffer@5.2.1
├─ safer-buffer@2.1.2
├─ semver@7.5.4
├─ side-channel@1.0.4
├─ simple-concat@1.0.1
├─ simple-get@4.0.1
├─ sshpk@1.17.0
├─ stream-counter@1.0.0
├─ string_decoder@1.3.0
├─ strip-json-comments@2.0.1
├─ sync-request@3.0.1
├─ tar-fs@2.1.1
├─ tar-stream@2.2.0
├─ tar@6.2.0
├─ then-request@2.2.0
├─ tough-cookie@2.5.0
├─ tr46@0.0.3
├─ tweetnacl@0.14.5
├─ typedarray@0.0.6
├─ typical@4.0.0
├─ universalify@0.1.2
├─ uri-js@4.4.1
├─ url-parse@1.5.10
├─ util-deprecate@1.0.2
├─ uuid@3.4.0
├─ verror@1.10.0
├─ web-streams-polyfill@3.2.1
├─ webidl-conversions@3.0.1
├─ whatwg-url@5.0.0
└─ wrappy@1.0.2
Done in 9.31s.
PS C:\Users\root\Desktop\realm-11> node -e 'console.log("last line of code");'
last line of code
PS C:\Users\root\Desktop\realm-11> node -e 'require("realm");console.log("last line of code");'
last line of code
PS C:\Users\root\Desktop\realm-11> node -p 'process.versions'
{
  node: '16.20.1',
  v8: '9.4.146.26-node.26',
  uv: '1.43.0',
  zlib: '1.2.11',
  brotli: '1.0.9',
  ares: '1.19.1',
  modules: '93',
  nghttp2: '1.47.0',
  napi: '8',
  llhttp: '6.0.11',
  openssl: '1.1.1u+quic',
  cldr: '41.0',
  icu: '71.1',
  tz: '2022f',
  unicode: '14.0',
  ngtcp2: '0.8.1',
  nghttp3: '0.7.0'
}

@gvanderclay
Copy link

gvanderclay commented Sep 8, 2023

We are also having similar issues in jest when upgrading realm to v12. We get the following output for any test that involves realm:

Jest did not exit one second after the test run has completed.

'This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

And when we run jest with --detectOpenHandles the test just hangs.

We have followed the steps from the documentation linked above, and also attempted to use the undocumented clearTestState with no success. We do this by calling the following function in our afterEach call for every test:

import Realm, { flags } from 'realm';
flags.ALLOW_CLEAR_TEST_STATE = true;
export const destroyRealm = (realm: Realm, config: Realm.Configuration) => {
  try {
    realm.close();
    Realm.deleteFile(config);
    Realm.clearTestState();
  } catch (error) {
    if (error instanceof Error) {
      LOG.error('Error clearing realm test state, this can be ignored:', error.message);
    }
  }
  realmWrapper = null;
};

I also tried the steps outlined by @sergeysedoy97 and see the same result.

I would love to upgrade to v12, but this is currently a hard block on doing so.

@flaviomsb
Copy link

Got same issue and it's reproducible with even the suggested test example by the official docs.

@flaviomsb
Copy link

This is still an open issue and the only way to get tests to finish is by adding --detectOpenHandles --forceExit flags.

@gvanderclay
Copy link

Is there any update on this being investigated or plans for a fix? We're keen on upgrading to the latest realm but this issue is a significant blocker. Requiring the --detectOpenHandles --forceExit flags for tests isn't ideal as it potentially masks other legitimate issues.

@sync-by-unito sync-by-unito bot removed the Needs-Attention Reporter has responded. Review comment. label Mar 1, 2024
@kneth
Copy link
Member

kneth commented Apr 19, 2024

With v12.7.0 we have introduced the method Realm.shutdown() to gracefully terminate Realm

@kneth kneth closed this as completed Apr 19, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 19, 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