Skip to content

Commit f8fb19d

Browse files
committed
src: force gc for flaky (deadlock) tests
This patch adds a new flag `force_gc_for_test` (internal use for test purpose only) to force GC specifically for flaky tests that suffer from deadlock. The deadlock occurs when: 1. Main thread calls DrainTasks and executes worker tasks 2. Worker task needs memory allocation requiring GC 3. GC must run on main thread, but main thread is busy running the worker task
1 parent 59f00d7 commit f8fb19d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Diff for: src/node_options.cc

+4
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,10 @@ PerProcessOptionsParser::PerProcessOptionsParser(
11661166
"force FIPS crypto (cannot be disabled)",
11671167
&PerProcessOptions::force_fips_crypto,
11681168
kAllowedInEnvvar);
1169+
AddOption("--force-gc-for-test",
1170+
"",
1171+
&PerProcessOptions::force_gc_for_test,
1172+
kAllowedInEnvvar);
11691173
AddOption("--secure-heap",
11701174
"total size of the OpenSSL secure heap",
11711175
&PerProcessOptions::secure_heap,

Diff for: src/node_options.h

+1
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ class PerProcessOptions : public Options {
321321
std::string snapshot_blob;
322322

323323
std::vector<std::string> security_reverts;
324+
bool force_gc_for_test = false;
324325
bool print_bash_completion = false;
325326
bool print_help = false;
326327
bool print_v8_help = false;

Diff for: src/node_platform.cc

+7
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,16 @@ void NodePlatform::DrainTasks(Isolate* isolate) {
463463
std::shared_ptr<PerIsolatePlatformData> per_isolate = ForNodeIsolate(isolate);
464464
if (!per_isolate) return;
465465

466+
466467
do {
468+
if (per_process::cli_options->force_gc_for_test) {
469+
isolate->RequestGarbageCollectionForTesting(
470+
Isolate::GarbageCollectionType::kFullGarbageCollection);
471+
}
472+
467473
// Worker tasks aren't associated with an Isolate.
468474
worker_thread_task_runner_->BlockingDrain();
475+
469476
} while (per_isolate->FlushForegroundTasksInternal());
470477
}
471478

0 commit comments

Comments
 (0)