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