node-pty
node-pty copied to clipboard
node-pty freezes when using pty.spawn under the VS Code debugger on Windows
Environment details
- OS: Windows
- OS version: 10.0.19044.2604
- node-pty version: 1.0.0
- node version: 18.16.0
- VS Code version: 1.84.2
Issue description
When running the example snippet from the node-pty documentation under the VS Code debugger, my script freezes on the call to pty.spawn.
const ptyProcess = pty.spawn(shell, [], { name: 'xterm-color', cols: 80, rows: 30, cwd: process.env.HOME, env: process.env });
Through some investigation, it appears this issue is related to the use of conpty. The exact line where the freeze occurs is in windowsPtyAgent.js:
var connect = this._ptyNative.connect(this._pty, commandLine, cwd, env, function (c) { return _this._$onProcessExit(c); });
Interestingly, if a breakpoint is set on this line, the script will continue execution normally after the breakpoint is hit and the program is resumed. The script also runs without any problems when the VS Code debugger is not used.
As a temporary workaround, the freezing issue can be mitigated by disabling conpty when running under debugger by useConpty in the options passed to the pty.spawn function. However, this is not an ideal fix as it prevents the usage of conpty.
useConpty: inspector.url() !== undefined ? false : undefined,
Seeing this as well. Works fine when built, but hangs in the debugger.