From 81de6645ba2cac0718c2184bc5c149ac69a94cf8 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Fri, 25 Aug 2023 12:27:21 -0700 Subject: [PATCH 1/2] Move disconnect code to OnProcessExit --- src/win/conpty.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/win/conpty.cc b/src/win/conpty.cc index 6f36a0d25..7c5f0bfb6 100644 --- a/src/win/conpty.cc +++ b/src/win/conpty.cc @@ -257,6 +257,12 @@ static void OnProcessExit(uv_async_t *async) { DWORD exitCode = 0; GetExitCodeProcess(baton->hShell, &exitCode); + // Clean up handles + DisconnectNamedPipe(baton->hIn); + DisconnectNamedPipe(baton->hOut); + CloseHandle(baton->hIn); + CloseHandle(baton->hOut); + // Call function v8::Local args[1] = { Nan::New(exitCode) @@ -476,10 +482,6 @@ static NAN_METHOD(PtyKill) { } } - DisconnectNamedPipe(handle->hIn); - DisconnectNamedPipe(handle->hOut); - CloseHandle(handle->hIn); - CloseHandle(handle->hOut); CloseHandle(handle->hShell); } From 41ec9dc4f16faf518dfe4155be49e516e6810bf1 Mon Sep 17 00:00:00 2001 From: Raymond Zhao <7199958+rzhao271@users.noreply.github.com> Date: Fri, 25 Aug 2023 13:46:16 -0700 Subject: [PATCH 2/2] Tested the PR. Add comment --- src/win/conpty.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/win/conpty.cc b/src/win/conpty.cc index 7c5f0bfb6..f614cc4af 100644 --- a/src/win/conpty.cc +++ b/src/win/conpty.cc @@ -258,8 +258,9 @@ static void OnProcessExit(uv_async_t *async) { GetExitCodeProcess(baton->hShell, &exitCode); // Clean up handles - DisconnectNamedPipe(baton->hIn); - DisconnectNamedPipe(baton->hOut); + // Calling DisconnectNamedPipes here or in PtyKill results in a crash, + // ref https://github.com/microsoft/node-pty/issues/512, + // so we only call CloseHandle for now. CloseHandle(baton->hIn); CloseHandle(baton->hOut);