Skip to content

inspector: process.exit should wait for inspector #7252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ static v8::Platform* default_platform;

#ifdef __POSIX__
static uv_sem_t debug_semaphore;
static const unsigned kMaxSignal = 32;
#endif

static void PrintErrorString(const char* format, ...) {
Expand Down Expand Up @@ -2094,7 +2095,29 @@ static void InitGroups(const FunctionCallbackInfo<Value>& args) {
#endif // __POSIX__ && !defined(__ANDROID__)


static void WaitForInspectorDisconnect(Environment* env) {
#if HAVE_INSPECTOR
if (env->inspector_agent()->IsConnected()) {
// Restore signal dispositions, the app is done and is no longer
// capable of handling signals.
#ifdef __POSIX__
struct sigaction act;
memset(&act, 0, sizeof(act));
for (unsigned nr = 1; nr < kMaxSignal; nr += 1) {
if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF)
continue;
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
CHECK_EQ(0, sigaction(nr, &act, nullptr));
}
#endif
env->inspector_agent()->WaitForDisconnect();
}
#endif
}


void Exit(const FunctionCallbackInfo<Value>& args) {
WaitForInspectorDisconnect(Environment::GetCurrent(args));
exit(args[0]->Int32Value());
}

Expand Down Expand Up @@ -3987,7 +4010,7 @@ inline void PlatformInit() {
// The hard-coded upper limit is because NSIG is not very reliable; on Linux,
// it evaluates to 32, 34 or 64, depending on whether RT signals are enabled.
// Counting up to SIGRTMIN doesn't work for the same reason.
for (unsigned nr = 1; nr < 32; nr += 1) {
for (unsigned nr = 1; nr < kMaxSignal; nr += 1) {
if (nr == SIGKILL || nr == SIGSTOP)
continue;
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
Expand Down Expand Up @@ -4297,24 +4320,7 @@ static void StartNodeInstance(void* arg) {
instance_data->set_exit_code(exit_code);
RunAtExit(&env);

#if HAVE_INSPECTOR
if (env.inspector_agent()->IsConnected()) {
// Restore signal dispositions, the app is done and is no longer
// capable of handling signals.
#ifdef __POSIX__
struct sigaction act;
memset(&act, 0, sizeof(act));
for (unsigned nr = 1; nr < 32; nr += 1) {
if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF)
continue;
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
CHECK_EQ(0, sigaction(nr, &act, nullptr));
}
#endif
env.inspector_agent()->WaitForDisconnect();
}
#endif

WaitForInspectorDisconnect(&env);
#if defined(LEAK_SANITIZER)
__lsan_do_leak_check();
#endif
Expand Down