Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/node_platform.cc
Original file line numberDiff line numberDiff line change
Expand Up@@ -117,6 +117,8 @@ class WorkerThreadsTaskRunner::DelayedTaskScheduler {
double delay_in_seconds) {
auto locked = tasks_.Lock();

if (has_shut_down_) return;

auto entry = std::make_unique<TaskQueueEntry>(std::move(task), priority);
auto delayed = std::make_unique<ScheduleTask>(
this, std::move(entry), delay_in_seconds);
Expand All@@ -132,6 +134,7 @@ class WorkerThreadsTaskRunner::DelayedTaskScheduler {

void Stop() {
auto locked = tasks_.Lock();
has_shut_down_ = true;
locked.Push(std::make_unique<StopTask>(this));
uv_async_send(&flush_tasks_);
}
Expand DownExpand Up@@ -241,6 +244,7 @@ class WorkerThreadsTaskRunner::DelayedTaskScheduler {
uv_loop_t loop_;
uv_async_t flush_tasks_;
std::unordered_set<uv_timer_t*> timers_;
bool has_shut_down_ = false;
};

WorkerThreadsTaskRunner::WorkerThreadsTaskRunner(
Expand Down
32 changes: 32 additions & 0 deletions test/parallel/test-process-exit-after-fetch-throw.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
'use strict';
// Ref: https://github.com/nodejs/node/issues/56645
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
const http = require('http');

if (process.argv[2] === 'child') {
http
.createServer((_, res) => {
res.writeHead(302, { Location: '/' });
res.end();
})
.listen(0, '127.0.0.1', async function() {
try {
await fetch(`http://127.0.0.1:${this.address().port}/`);
} catch {
// ignore
}
process.exit(0);
});
} else {
const child = cp.spawn(process.execPath, [__filename, 'child']);

child.on(
'close',
common.mustCall((exitCode, signal) => {
assert.strictEqual(exitCode, 0);
assert.strictEqual(signal, null);
}),
);
}
Loading