Skip to content

Commit 037ac99

Browse files
committed
embedding: make Stop() stop Workers
This makes sense given that terminating execution of the parent thread this way likely also is supposed to stop all running Worker threads spawned by it. PR-URL: #32531 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d812f16 commit 037ac99

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

src/api/environment.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -725,8 +725,7 @@ ThreadId AllocateEnvironmentThreadId() {
725725
}
726726

727727
void DefaultProcessExitHandler(Environment* env, int exit_code) {
728-
env->set_can_call_into_js(false);
729-
env->stop_sub_worker_contexts();
728+
Stop(env);
730729
DisposePlatform();
731730
exit(exit_code);
732731
}

src/env.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,10 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
501501
}
502502
}
503503

504-
void Environment::ExitEnv() {
504+
void Environment::Stop() {
505505
set_can_call_into_js(false);
506506
set_stopping(true);
507+
stop_sub_worker_contexts();
507508
isolate_->TerminateExecution();
508509
SetImmediateThreadsafe([](Environment* env) { uv_stop(env->event_loop()); });
509510
}

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ class Environment : public MemoryRetainer {
897897
void RegisterHandleCleanups();
898898
void CleanupHandles();
899899
void Exit(int code);
900-
void ExitEnv();
900+
void Stop();
901901

902902
// Register clean-up cb to be called on environment destruction.
903903
inline void RegisterHandleCleanup(uv_handle_t* handle,

src/node.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ int Start(int argc, char** argv) {
10591059
}
10601060

10611061
int Stop(Environment* env) {
1062-
env->ExitEnv();
1062+
env->Stop();
10631063
return 0;
10641064
}
10651065

src/node.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ class Environment;
224224
NODE_EXTERN int Start(int argc, char* argv[]);
225225

226226
// Tear down Node.js while it is running (there are active handles
227-
// in the loop and / or actively executing JavaScript code).
227+
// in the loop and / or actively executing JavaScript code). This also stops
228+
// all Workers that may have been started earlier.
228229
NODE_EXTERN int Stop(Environment* env);
229230

230231
// TODO(addaleax): Officially deprecate this and replace it with something
@@ -478,8 +479,8 @@ NODE_EXTERN void FreeEnvironment(Environment* env);
478479
// It receives the Environment* instance and the exit code as arguments.
479480
// This could e.g. call Stop(env); in order to terminate execution and stop
480481
// the event loop.
481-
// The default handler disposes of the global V8 platform instance, if one is
482-
// being used, and calls exit().
482+
// The default handler calls Stop(), disposes of the global V8 platform
483+
// instance, if one is being used, and calls exit().
483484
NODE_EXTERN void SetProcessExitHandler(
484485
Environment* env,
485486
std::function<void(Environment*, int)>&& handler);

0 commit comments

Comments
 (0)