Skip to content

Commit

Permalink
fix: assertion on node environment shutdown (microsoft#672)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 authored Mar 7, 2024
1 parent 2dab380 commit 783c7ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions src/unix/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,22 @@ void SetupExitCallback(Napi::Env env, Napi::Function cb, pid_t pid) {
exit_event->signal_code = WTERMSIG(stat_loc);
}
auto status = tsfn.BlockingCall(exit_event, callback); // In main thread
assert(status == napi_ok);
switch (status) {
case napi_closing:
break;

tsfn.Release();
case napi_queue_full:
Napi::Error::Fatal("SetupExitCallback", "Queue was full");

case napi_ok:
if (tsfn.Release() != napi_ok) {
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.Release() failed");
}
break;

default:
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.BlockingCall() failed");
}
});
}

Expand Down
17 changes: 15 additions & 2 deletions src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,22 @@ void SetupExitCallback(Napi::Env env, Napi::Function cb, pty_baton* baton) {
CloseHandle(baton->hOut);

auto status = tsfn.BlockingCall(exit_event, callback); // In main thread
assert(status == napi_ok);
switch (status) {
case napi_closing:
break;

tsfn.Release();
case napi_queue_full:
Napi::Error::Fatal("SetupExitCallback", "Queue was full");

case napi_ok:
if (tsfn.Release() != napi_ok) {
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.Release() failed");
}
break;

default:
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.BlockingCall() failed");
}
});
}

Expand Down

0 comments on commit 783c7ed

Please sign in to comment.