Skip to content

NodeWorker domain pauses on start unless there's an --require'd program in NODE_OPTIONS #38934

Open
@connor4312

Description

@connor4312
  • Version: 16.2.0
  • Platform: Microsoft Windows NT 10.0.19042.0 x64
  • Subsystem: inspector

This is probably similar to #38420, but reporting it for visibility.

What steps will reproduce the bug?

In a debugger that's worker_thread capable, namely in VS Code:

  1. Create these files:

    index.js

    const { Worker, isMainThread } = require('worker_threads');
    
    if (isMainThread) {
      const worker = new Worker(__filename, {
        // env: {}
      });
    } else {
      console.log('hello world');
    }

    empty.js

    .vscode/launch.json

    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": "Launch Program",
          "program": "${workspaceFolder}/index.js",
          "request": "launch",
          "type": "pwa-node"
        }
      ]
    }
  2. Debug it (by hitting F5). It should run through and exit.

  3. Uncomment line 5. Debug it. It pauses when the worker thread is launched. 🐛

  4. Replace line 5 with env: { NODE_OPTIONS: --require ${__dirname}/empty.js }. Debug it. It no longer pauses.

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

100%

What is the expected behavior?

In no case should the debugger pause when entering the worker_thread.

What do you see instead?

It pauses if there is nothing --required in the NODE_OPTIONS. But even requiring an empty file, which I would expect to have no effect, fixes the issue.

Additional information

This is the "paused" event sent from Node in the env: {} case:

{
  "method": "Debugger.paused",
  "params": {
    "callFrames": [
      {
        "callFrameId": "-1076361671936602912.1.0",
        "functionName": "",
        "functionLocation": {
          "scriptId": "102",
          "lineNumber": 0,
          "columnNumber": 0
        },
        "location": {
          "scriptId": "102",
          "lineNumber": 0,
          "columnNumber": 33
        },
        "url": "file:///e:/Downloads/vscode-debug-test/index.js",
        "scopeChain": [
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.1"
            },
            "startLocation": {
              "scriptId": "102",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "102",
              "lineNumber": 9,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.2"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "Object",
          "description": "Object",
          "objectId": "-1076361671936602912.1.3"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.1",
        "functionName": "Module._compile",
        "functionLocation": {
          "scriptId": "79",
          "lineNumber": 1062,
          "columnNumber": 36
        },
        "location": {
          "scriptId": "79",
          "lineNumber": 1105,
          "columnNumber": 13
        },
        "url": "node:internal/modules/cjs/loader",
        "scopeChain": [
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.4"
            },
            "name": "Module._compile",
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 1062,
              "columnNumber": 36
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 1114,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.5"
            },
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 1274,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.6"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "Module",
          "description": "Module",
          "objectId": "-1076361671936602912.1.7"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.2",
        "functionName": "Module._extensions..js",
        "functionLocation": {
          "scriptId": "79",
          "lineNumber": 1117,
          "columnNumber": 36
        },
        "location": {
          "scriptId": "79",
          "lineNumber": 1137,
          "columnNumber": 9
        },
        "url": "node:internal/modules/cjs/loader",
        "scopeChain": [
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.8"
            },
            "name": "Module._extensions..js",
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 1117,
              "columnNumber": 36
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 1138,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.9"
            },
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 1274,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.10"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "Object",
          "description": "Object",
          "objectId": "-1076361671936602912.1.11"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.3",
        "functionName": "Module.load",
        "functionLocation": {
          "scriptId": "79",
          "lineNumber": 976,
          "columnNumber": 32
        },
        "location": {
          "scriptId": "79",
          "lineNumber": 988,
          "columnNumber": 31
        },
        "url": "node:internal/modules/cjs/loader",
        "scopeChain": [
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.12"
            },
            "name": "Module.load",
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 976,
              "columnNumber": 32
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 999,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.13"
            },
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 1274,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.14"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "Module",
          "description": "Module",
          "objectId": "-1076361671936602912.1.15"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.4",
        "functionName": "Module._load",
        "functionLocation": {
          "scriptId": "79",
          "lineNumber": 752,
          "columnNumber": 23
        },
        "location": {
          "scriptId": "79",
          "lineNumber": 828,
          "columnNumber": 13
        },
        "url": "node:internal/modules/cjs/loader",
        "scopeChain": [
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.16"
            },
            "name": "Module._load",
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 752,
              "columnNumber": 23
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 853,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.17"
            },
            "startLocation": {
              "scriptId": "79",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "79",
              "lineNumber": 1274,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.18"
            }
          }
        ],
        "this": {
          "type": "function",
          "className": "Function",
          "description": "function Module(id = '', parent) {\r\n  this.id = id;\r\n  this.path = path.dirname(id);\r\n  this.exports = {};\r\n  moduleParentCache.set(this, parent);\r\n  updateChildren(parent, this, false);\r\n  this.filename = null;\r\n  this.loaded = false;\r\n  this.children = [];\r\n}",
          "objectId": "-1076361671936602912.1.19"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.5",
        "functionName": "executeUserEntryPoint",
        "functionLocation": {
          "scriptId": "101",
          "lineNumber": 68,
          "columnNumber": 30
        },
        "location": {
          "scriptId": "101",
          "lineNumber": 75,
          "columnNumber": 11
        },
        "url": "node:internal/modules/run_main",
        "scopeChain": [
          {
            "type": "block",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.20"
            },
            "name": "executeUserEntryPoint",
            "startLocation": {
              "scriptId": "101",
              "lineNumber": 68,
              "columnNumber": 55
            },
            "endLocation": {
              "scriptId": "101",
              "lineNumber": 77,
              "columnNumber": 1
            }
          },
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.21"
            },
            "name": "executeUserEntryPoint",
            "startLocation": {
              "scriptId": "101",
              "lineNumber": 68,
              "columnNumber": 30
            },
            "endLocation": {
              "scriptId": "101",
              "lineNumber": 77,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.22"
            },
            "startLocation": {
              "scriptId": "101",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "101",
              "lineNumber": 83,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.23"
            }
          }
        ],
        "this": {
          "type": "function",
          "className": "Function",
          "description": "function Module(id = '', parent) {\r\n  this.id = id;\r\n  this.path = path.dirname(id);\r\n  this.exports = {};\r\n  moduleParentCache.set(this, parent);\r\n  updateChildren(parent, this, false);\r\n  this.filename = null;\r\n  this.loaded = false;\r\n  this.children = [];\r\n}",
          "objectId": "-1076361671936602912.1.24"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.6",
        "functionName": "",
        "functionLocation": {
          "scriptId": "71",
          "lineNumber": 99,
          "columnNumber": 19
        },
        "location": {
          "scriptId": "71",
          "lineNumber": 182,
          "columnNumber": 23
        },
        "url": "node:internal/main/worker_thread",
        "scopeChain": [
          {
            "type": "block",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.25"
            },
            "startLocation": {
              "scriptId": "71",
              "lineNumber": 100,
              "columnNumber": 36
            },
            "endLocation": {
              "scriptId": "71",
              "lineNumber": 184,
              "columnNumber": 3
            }
          },
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.26"
            },
            "startLocation": {
              "scriptId": "71",
              "lineNumber": 99,
              "columnNumber": 19
            },
            "endLocation": {
              "scriptId": "71",
              "lineNumber": 197,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.27"
            },
            "startLocation": {
              "scriptId": "71",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "71",
              "lineNumber": 252,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.28"
            }
          }
        ],
        "this": {
          "type": "undefined"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.7",
        "functionName": "[nodejs.internal.kHybridDispatch]",
        "functionLocation": {
          "scriptId": "37",
          "lineNumber": 413,
          "columnNumber": 19
        },
        "location": {
          "scriptId": "37",
          "lineNumber": 460,
          "columnNumber": 19
        },
        "url": "node:internal/event_target",
        "scopeChain": [
          {
            "type": "block",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.29"
            },
            "name": "[nodejs.internal.kHybridDispatch]",
            "startLocation": {
              "scriptId": "37",
              "lineNumber": 449,
              "columnNumber": 10
            },
            "endLocation": {
              "scriptId": "37",
              "lineNumber": 464,
              "columnNumber": 7
            }
          },
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.30"
            },
            "name": "[nodejs.internal.kHybridDispatch]",
            "startLocation": {
              "scriptId": "37",
              "lineNumber": 413,
              "columnNumber": 19
            },
            "endLocation": {
              "scriptId": "37",
              "lineNumber": 473,
              "columnNumber": 3
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.31"
            },
            "startLocation": {
              "scriptId": "37",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "37",
              "lineNumber": 720,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.32"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "MessagePort",
          "description": "MessagePort",
          "objectId": "-1076361671936602912.1.33"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.8",
        "functionName": "exports.emitMessage",
        "functionLocation": {
          "scriptId": "8",
          "lineNumber": 18,
          "columnNumber": 30
        },
        "location": {
          "scriptId": "8",
          "lineNumber": 22,
          "columnNumber": 27
        },
        "url": "",
        "scopeChain": [
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.34"
            },
            "name": "exports.emitMessage",
            "startLocation": {
              "scriptId": "8",
              "lineNumber": 18,
              "columnNumber": 30
            },
            "endLocation": {
              "scriptId": "8",
              "lineNumber": 38,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.35"
            },
            "startLocation": {
              "scriptId": "8",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "8",
              "lineNumber": 39,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.36"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "MessagePort",
          "description": "MessagePort",
          "objectId": "-1076361671936602912.1.37"
        }
      },
      {
        "callFrameId": "-1076361671936602912.1.9",
        "functionName": "callbackTrampoline",
        "functionLocation": {
          "scriptId": "24",
          "lineNumber": 117,
          "columnNumber": 27
        },
        "location": {
          "scriptId": "24",
          "lineNumber": 129,
          "columnNumber": 16
        },
        "url": "node:internal/async_hooks",
        "scopeChain": [
          {
            "type": "block",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.38"
            },
            "name": "callbackTrampoline",
            "startLocation": {
              "scriptId": "24",
              "lineNumber": 117,
              "columnNumber": 60
            },
            "endLocation": {
              "scriptId": "24",
              "lineNumber": 137,
              "columnNumber": 1
            }
          },
          {
            "type": "local",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.39"
            },
            "name": "callbackTrampoline",
            "startLocation": {
              "scriptId": "24",
              "lineNumber": 117,
              "columnNumber": 27
            },
            "endLocation": {
              "scriptId": "24",
              "lineNumber": 137,
              "columnNumber": 1
            }
          },
          {
            "type": "closure",
            "object": {
              "type": "object",
              "className": "Object",
              "description": "Object",
              "objectId": "-1076361671936602912.1.40"
            },
            "startLocation": {
              "scriptId": "24",
              "lineNumber": 0,
              "columnNumber": 0
            },
            "endLocation": {
              "scriptId": "24",
              "lineNumber": 591,
              "columnNumber": 0
            }
          },
          {
            "type": "global",
            "object": {
              "type": "object",
              "className": "global",
              "description": "global",
              "objectId": "-1076361671936602912.1.41"
            }
          }
        ],
        "this": {
          "type": "object",
          "className": "MessagePort",
          "description": "MessagePort",
          "objectId": "-1076361671936602912.1.42"
        }
      }
    ],
    "reason": "Break on start",
    "hitBreakpoints": []
  }
}

You can add trace: true to the launch.json, which will produce a file containing all traffic to and from the debugger that can be inspected here.

Note that the program is not launched with --inspect-brk (in which case this behavior would be expected)

This was originally reported in microsoft/vscode#125451

Metadata

Metadata

Assignees

No one assigned

    Labels

    workerIssues and PRs related to Worker support.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions