From: aardizio Date: Thu, 18 Feb 2021 13:21:23 +0000 (+0100) Subject: Fix EPIPE on shutdown X-Git-Tag: v2.0.0-beta.2~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4dc274761ce688172117009d1b306077d321f461;p=poolifier.git Fix EPIPE on shutdown --- diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 03d954fe..0a6530e3 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -41,6 +41,11 @@ export abstract class AbstractWorker< */ protected readonly interval?: NodeJS.Timeout + /** + * This value is immediately set to true when the kill from the main worker is received. + */ + private isKilled: boolean = false + /** * Constructs a new poolifier worker. * @@ -90,6 +95,7 @@ export abstract class AbstractWorker< this.mainWorker = value.parent } else if (value.kill) { // Here is time to kill this worker, just clearing the interval + this.isKilled = true if (this.interval) clearInterval(this.interval) this.emitDestroy() } @@ -128,7 +134,7 @@ export abstract class AbstractWorker< * Check to see if the worker should be terminated, because its living too long. */ protected checkAlive (): void { - if (Date.now() - this.lastTask > this.maxInactiveTime) { + if (Date.now() - this.lastTask > this.maxInactiveTime && !this.isKilled) { this.sendToMainWorker({ kill: this.killBehavior }) } }