Skip to content

Conversation

@adityamandaleeka
Copy link
Member

@adityamandaleeka adityamandaleeka commented Feb 3, 2026

(Note: this is my first PR here so apologies in advance if I missed any important steps!)

ConnectNamedPipe blocks the Node.js event loop when called before the worker thread has connected to the output pipe. This causes spawning PTYs to freeze, particularly noticeable when using a debugger (as in the original issue report) and when running parallel processes with limited CPU cores (e.g. in CI environments).

This change defers the call to conptyNative.connect() until the worker signals it's ready via the onReady callback. At that point, ConnectNamedPipe returns immediately because the client is already connected.

The new tests added in this PR fail without the fix (innerPid is immediately set to a real PID) and pass with it.

Fix #763

adityamandaleeka and others added 8 commits February 1, 2026 19:41
Fixes microsoft#763

The issue was that conptyNative.connect() called ConnectNamedPipe()
synchronously for both input and output pipes. While the input pipe
was connected via fs.openSync() before the call, the output pipe
connection happened asynchronously in a worker thread.

If the worker thread hadn't connected yet when ConnectNamedPipe was
called, it would block the Node.js event loop waiting for the connection.
This caused a deadlock when a debugger was attached (which slows down
the event loop and worker thread startup).

The fix defers the conptyNative.connect() call until the worker thread
signals it has connected to the output pipe (via the onReady callback).
This ensures both pipes have clients connected before ConnectNamedPipe
is called, so it returns immediately without blocking.
If the worker fails to signal ready within 5 seconds, complete the
connection anyway to avoid leaving the PTY in a zombie state.
Clear _pendingPtyInfo in kill() to prevent the timeout or onReady
callback from calling connect() on an already-killed PTY handle.
The public pid property was only set once at construction, before the
deferred connection. Update it in the ready_datapipe handler so users
get the correct pid value.
Add test to ensure WindowsTerminal.pid is correctly updated after the
deferred connection completes. This closes the test coverage gap for
the public pid property.
@Tyriar Tyriar added this to the 1.2.0 milestone Feb 3, 2026
@Tyriar Tyriar self-assigned this Feb 3, 2026
@Tyriar Tyriar enabled auto-merge February 3, 2026 12:44
@Tyriar Tyriar merged commit 59b2542 into microsoft:main Feb 3, 2026
9 checks passed
@adityamandaleeka
Copy link
Member Author

Thanks for the quick reviews! 🚀

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

Successfully merging this pull request may close these issues.

freeze when using debugger on windows

3 participants