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

ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE after require('repl') or require('domain') #48131

Open
cspotcode opened this issue May 23, 2023 · 1 comment

Comments

@cspotcode
Copy link

Version

16.20.0, 17.9.1, 18.16.0, 19.9.0, 20.2.0

Platform

Windows

Subsystem

No response

What steps will reproduce the bug?

Do either of the following:

node -e 'require("domain"); process.setUncaughtExceptionCaptureCallback(function() {})'

Or, if you believe the user should not be using the domain module, then it also happens when they import (not use!) "repl"

node -e 'require("repl"); process.setUncaughtExceptionCaptureCallback(function() {})'

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

Merely requiring repl does not trigger this side-effect, because it is expected that merely requiring -- not using -- the repl module would not break process.setUncaughtExceptionCaptureCallback

What do you see instead?

Error [ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE]: The `domain` module is in use, which is mutually exclusive with calling process.setUncaughtExceptionCaptureCallback()
    at new NodeError (node:internal/errors:372:5)
    at process.setUncaughtExceptionCaptureCallback (node:domain:125:15)
    at [eval]:1:26
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:76:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60)
    at node:internal/main/eval_string:27:3
----------------------------------------
Error: require(`domain`) at this point
    at node:domain:121:28
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at nativeModuleRequire (node:internal/bootstrap/loaders:341:14)
    at node:repl:132:16
    at NativeModule.compileForInternalLoader (node:internal/bootstrap/loaders:312:7)
    at NativeModule.compileForPublicLoader (node:internal/bootstrap/loaders:252:10)
    at loadNativeModule (node:internal/modules/cjs/helpers:49:9)
    at Function.Module._load (node:internal/modules/cjs/loader:804:15)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18) {
  code: 'ERR_DOMAIN_CANNOT_SET_UNCAUGHT_EXCEPTION_CAPTURE'
}

Additional information

Related to TypeStrong/ts-node#2024

@isaacs
Copy link
Contributor

isaacs commented May 23, 2023

There are """reasons""" (not good ones, but old ones) as to why require('domain') has side effects. And somewhat more justifiable reasons as to why using a repl triggers them as well. But at the very least, I think repl should load domain lazily.

(Istr that there's a plan to get domain out of repl, and that's one of the last few things keeping domain from being fully removed? Maybe along with the lack of an alternative, though at this point, they've been broken enough for long enough that it's probably safe to say no one is using them in a real way.)

isaacs added a commit to isaacs/ts-node that referenced this issue May 23, 2023
Actually starting the repl will still put the process into domain-mode,
but this at least allows programs to use `ts-node` or
`--loader=ts-node/esm` without losing the ability to use
process.setUncaughtExceptionCaptureCallback().

The problem should ideally be fixed (or mitigated) in node core, but
this is still worthwhile for the benefit of supporting current node
versions.

Re: nodejs/node#48131
Fix: TypeStrong#2024
isaacs added a commit to isaacs/ts-node that referenced this issue May 24, 2023
Actually starting the repl will still put the process into domain-mode,
but this at least allows programs to use `ts-node` or
`--loader=ts-node/esm` without losing the ability to use
process.setUncaughtExceptionCaptureCallback().

The problem should ideally be fixed (or mitigated) in node core, but
this is still worthwhile for the benefit of supporting current node
versions.

Re: nodejs/node#48131
Fix: TypeStrong#2024
cspotcode added a commit to TypeStrong/ts-node that referenced this issue May 30, 2023
* fix: lazy-load repl to avoid domain side effects

Actually starting the repl will still put the process into domain-mode,
but this at least allows programs to use `ts-node` or
`--loader=ts-node/esm` without losing the ability to use
process.setUncaughtExceptionCaptureCallback().

The problem should ideally be fixed (or mitigated) in node core, but
this is still worthwhile for the benefit of supporting current node
versions.

Re: nodejs/node#48131
Fix: #2024

* Update src/repl.ts

---------

Co-authored-by: Andrew Bradley <cspotcode@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@isaacs @cspotcode and others