Skip to content

Commit

Permalink
Add explicit process.exit() to avoid wait for hanging promises
Browse files Browse the repository at this point in the history
When using the `@actions/cache` library to save cache entries, it seems that one
or more Promises remain unresolved after the save completes.
With Node20 this causes a delay when exiting the process: the default behaviour
now wait for these Promises to complete. Adding an explicit `Process.exit()`
removes the delay, returning to the Node 16 behaviour.

Fixes #1038
  • Loading branch information
bigdaz committed Jan 17, 2024
1 parent 3466457 commit 19cefc1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140762,10 +140762,10 @@ function run() {
core.info(error.stack);
}
}
process.exit();
});
}
exports.run = run;
run();


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js.map

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions dist/post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138072,10 +138072,12 @@ function run() {
catch (error) {
if (error instanceof errors_1.PostActionJobFailure) {
core.setFailed(String(error));
return;
}
handleFailure(error);
else {
handleFailure(error);
}
}
process.exit();
});
}
exports.run = run;
Expand All @@ -138085,7 +138087,6 @@ function handleFailure(error) {
core.info(error.stack);
}
}
run();


/***/ }),
Expand Down
2 changes: 1 addition & 1 deletion dist/post/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function run(): Promise<void> {
core.info(error.stack)
}
}
}

run()
// Explicit process.exit() to prevent waiting for hanging promises.
process.exit()
}
10 changes: 5 additions & 5 deletions src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export async function run(): Promise<void> {
} catch (error) {
if (error instanceof PostActionJobFailure) {
core.setFailed(String(error))
return
} else {
handleFailure(error)
}

handleFailure(error)
}

// Explicit process.exit() to prevent waiting for promises left hanging by `@actions/cache` on save.
process.exit()
}

function handleFailure(error: unknown): void {
Expand All @@ -29,5 +31,3 @@ function handleFailure(error: unknown): void {
core.info(error.stack)
}
}

run()

0 comments on commit 19cefc1

Please sign in to comment.