Skip to content

Commit 483fc43

Browse files
authored
fix: force quit stuck Actor.exit() calls (#420)
These changes place the `process.exit()` call into the event loop before any potentially time-consuming operations.
1 parent 2eb6fef commit 483fc43

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/apify/src/actor.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,15 @@ export class Actor<Data extends Dictionary = Dictionary> {
553553
log.debug(
554554
`Waiting for all event listeners to complete their execution (with ${options.timeoutSecs} seconds timeout)`,
555555
);
556+
557+
if (options.exit) {
558+
// `addTimeoutToPromise` is a cooperative timeout. This ensures that the process exits
559+
// after the timeout, even if the event listeners don't trigger the timeout.
560+
setTimeout(() => {
561+
process.exit(options.exitCode);
562+
}, options.timeoutSecs * 1000);
563+
}
564+
556565
await addTimeoutToPromise(
557566
async () => {
558567
await events.waitForAllListenersToComplete();

0 commit comments

Comments
 (0)