Skip to content

Commit 783c7ed

Browse files
authored
fix: assertion on node environment shutdown (microsoft#672)
1 parent 2dab380 commit 783c7ed

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

src/unix/pty.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,22 @@ void SetupExitCallback(Napi::Env env, Napi::Function cb, pid_t pid) {
189189
exit_event->signal_code = WTERMSIG(stat_loc);
190190
}
191191
auto status = tsfn.BlockingCall(exit_event, callback); // In main thread
192-
assert(status == napi_ok);
192+
switch (status) {
193+
case napi_closing:
194+
break;
193195

194-
tsfn.Release();
196+
case napi_queue_full:
197+
Napi::Error::Fatal("SetupExitCallback", "Queue was full");
198+
199+
case napi_ok:
200+
if (tsfn.Release() != napi_ok) {
201+
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.Release() failed");
202+
}
203+
break;
204+
205+
default:
206+
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.BlockingCall() failed");
207+
}
195208
});
196209
}
197210

src/win/conpty.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,22 @@ void SetupExitCallback(Napi::Env env, Napi::Function cb, pty_baton* baton) {
107107
CloseHandle(baton->hOut);
108108

109109
auto status = tsfn.BlockingCall(exit_event, callback); // In main thread
110-
assert(status == napi_ok);
110+
switch (status) {
111+
case napi_closing:
112+
break;
111113

112-
tsfn.Release();
114+
case napi_queue_full:
115+
Napi::Error::Fatal("SetupExitCallback", "Queue was full");
116+
117+
case napi_ok:
118+
if (tsfn.Release() != napi_ok) {
119+
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.Release() failed");
120+
}
121+
break;
122+
123+
default:
124+
Napi::Error::Fatal("SetupExitCallback", "ThreadSafeFunction.BlockingCall() failed");
125+
}
113126
});
114127
}
115128

0 commit comments

Comments
 (0)