Skip to content

Commit 6626919

Browse files
Eugene Ostroukhovofrobots
Eugene Ostroukhov
authored andcommitted
inspector: process.exit should wait for inspector
Fixes: #7088 PR-URL: #7252 Reviewed-By: bnoordhuis - Ben Noordhuis <[email protected]>
1 parent 0e9e149 commit 6626919

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

src/node.cc

+25-19
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ static v8::Platform* default_platform;
187187

188188
#ifdef __POSIX__
189189
static uv_sem_t debug_semaphore;
190+
static const unsigned kMaxSignal = 32;
190191
#endif
191192

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

20972098

2099+
static void WaitForInspectorDisconnect(Environment* env) {
2100+
#if HAVE_INSPECTOR
2101+
if (env->inspector_agent()->IsConnected()) {
2102+
// Restore signal dispositions, the app is done and is no longer
2103+
// capable of handling signals.
2104+
#ifdef __POSIX__
2105+
struct sigaction act;
2106+
memset(&act, 0, sizeof(act));
2107+
for (unsigned nr = 1; nr < kMaxSignal; nr += 1) {
2108+
if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF)
2109+
continue;
2110+
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
2111+
CHECK_EQ(0, sigaction(nr, &act, nullptr));
2112+
}
2113+
#endif
2114+
env->inspector_agent()->WaitForDisconnect();
2115+
}
2116+
#endif
2117+
}
2118+
2119+
20982120
void Exit(const FunctionCallbackInfo<Value>& args) {
2121+
WaitForInspectorDisconnect(Environment::GetCurrent(args));
20992122
exit(args[0]->Int32Value());
21002123
}
21012124

@@ -3992,7 +4015,7 @@ inline void PlatformInit() {
39924015
// The hard-coded upper limit is because NSIG is not very reliable; on Linux,
39934016
// it evaluates to 32, 34 or 64, depending on whether RT signals are enabled.
39944017
// Counting up to SIGRTMIN doesn't work for the same reason.
3995-
for (unsigned nr = 1; nr < 32; nr += 1) {
4018+
for (unsigned nr = 1; nr < kMaxSignal; nr += 1) {
39964019
if (nr == SIGKILL || nr == SIGSTOP)
39974020
continue;
39984021
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
@@ -4302,24 +4325,7 @@ static void StartNodeInstance(void* arg) {
43024325
instance_data->set_exit_code(exit_code);
43034326
RunAtExit(&env);
43044327

4305-
#if HAVE_INSPECTOR
4306-
if (env.inspector_agent()->IsConnected()) {
4307-
// Restore signal dispositions, the app is done and is no longer
4308-
// capable of handling signals.
4309-
#ifdef __POSIX__
4310-
struct sigaction act;
4311-
memset(&act, 0, sizeof(act));
4312-
for (unsigned nr = 1; nr < 32; nr += 1) {
4313-
if (nr == SIGKILL || nr == SIGSTOP || nr == SIGPROF)
4314-
continue;
4315-
act.sa_handler = (nr == SIGPIPE) ? SIG_IGN : SIG_DFL;
4316-
CHECK_EQ(0, sigaction(nr, &act, nullptr));
4317-
}
4318-
#endif
4319-
env.inspector_agent()->WaitForDisconnect();
4320-
}
4321-
#endif
4322-
4328+
WaitForInspectorDisconnect(&env);
43234329
#if defined(LEAK_SANITIZER)
43244330
__lsan_do_leak_check();
43254331
#endif

0 commit comments

Comments
 (0)