Skip to content

Commit 03bad86

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.
1 parent e87a6c2 commit 03bad86

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

src/api/environment.cc

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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)