From 271bc999c1a6c75f8e8359214237b51f8ade03c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Nesveda?= Date: Thu, 19 Dec 2024 16:04:19 +0100 Subject: [PATCH] fix: prevent reboot loops (#345) --- packages/apify/src/actor.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/apify/src/actor.ts b/packages/apify/src/actor.ts index d83143d821..2468774384 100644 --- a/packages/apify/src/actor.ts +++ b/packages/apify/src/actor.ts @@ -81,6 +81,11 @@ export class Actor { */ private warnedAboutMissingInitCall = false; + /** + * Set if the Actor is currently rebooting. + */ + private isRebooting = false; + constructor(options: ConfigurationOptions = {}) { // use default configuration object if nothing overridden (it fallbacks to env vars) this.config = Object.keys(options).length === 0 ? Configuration.getGlobalConfig() : new Configuration(options); @@ -459,6 +464,13 @@ export class Actor { return; } + if (this.isRebooting) { + log.debug('Actor is already rebooting, skipping the additional reboot call.'); + return; + } + + this.isRebooting = true; + // Waiting for all the listeners to finish, as `.reboot()` kills the container. await Promise.all([ // `persistState` for individual RequestLists, RequestQueue... instances to be persisted