Skip to content

Commit 93a23b9

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: nodejs#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 6d231db commit 93a23b9

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
@@ -712,8 +712,7 @@ ThreadId AllocateEnvironmentThreadId() {
712712
}
713713

714714
void DefaultProcessExitHandler(Environment* env, int exit_code) {
715-
env->set_can_call_into_js(false);
716-
env->stop_sub_worker_contexts();
715+
Stop(env);
717716
DisposePlatform();
718717
exit(exit_code);
719718
}

src/env.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,10 @@ void Environment::InitializeLibuv(bool start_profiler_idle_notifier) {
523523
}
524524
}
525525

526-
void Environment::ExitEnv() {
526+
void Environment::Stop() {
527527
set_can_call_into_js(false);
528528
set_stopping(true);
529+
stop_sub_worker_contexts();
529530
isolate_->TerminateExecution();
530531
SetImmediateThreadsafe([](Environment* env) { uv_stop(env->event_loop()); });
531532
}

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ class Environment : public MemoryRetainer {
913913
void RegisterHandleCleanups();
914914
void CleanupHandles();
915915
void Exit(int code);
916-
void ExitEnv();
916+
void Stop();
917917

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

src/node.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ int Start(int argc, char** argv) {
10351035
}
10361036

10371037
int Stop(Environment* env) {
1038-
env->ExitEnv();
1038+
env->Stop();
10391039
return 0;
10401040
}
10411041

src/node.h

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

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

224225
// TODO(addaleax): Officially deprecate this and replace it with something
@@ -457,8 +458,8 @@ NODE_EXTERN void FreeEnvironment(Environment* env);
457458
// It receives the Environment* instance and the exit code as arguments.
458459
// This could e.g. call Stop(env); in order to terminate execution and stop
459460
// the event loop.
460-
// The default handler disposes of the global V8 platform instance, if one is
461-
// being used, and calls exit().
461+
// The default handler calls Stop(), disposes of the global V8 platform
462+
// instance, if one is being used, and calls exit().
462463
NODE_EXTERN void SetProcessExitHandler(
463464
Environment* env,
464465
std::function<void(Environment*, int)>&& handler);

0 commit comments

Comments
 (0)