fix(core): Make sure task runner exits (#12123)

This commit is contained in:
Tomi Turtiainen 2024-12-10 13:00:18 +02:00 committed by GitHub
parent a50969b244
commit c5effca7d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,7 +11,7 @@ let runner: JsTaskRunner | undefined;
let isShuttingDown = false;
let errorReporter: ErrorReporter | undefined;
function createSignalHandler(signal: string) {
function createSignalHandler(signal: string, timeoutInS = 10) {
return async function onSignal() {
if (isShuttingDown) {
return;
@ -19,6 +19,11 @@ function createSignalHandler(signal: string) {
console.log(`Received ${signal} signal, shutting down...`);
setTimeout(() => {
console.error('Shutdown timeout reached, forcing shutdown...');
process.exit(1);
}, timeoutInS * 1000).unref();
isShuttingDown = true;
try {
if (runner) {
@ -56,7 +61,8 @@ void (async function start() {
runner = new JsTaskRunner(config);
runner.on('runner:reached-idle-timeout', () => {
void createSignalHandler('IDLE_TIMEOUT')();
// Use shorter timeout since we know we don't have any tasks running
void createSignalHandler('IDLE_TIMEOUT', 1)();
});
const { enabled, host, port } = config.baseRunnerConfig.healthcheckServer;