From 4dc274761ce688172117009d1b306077d321f461 Mon Sep 17 00:00:00 2001 From: aardizio Date: Thu, 18 Feb 2021 14:21:23 +0100 Subject: [PATCH] Fix EPIPE on shutdown --- src/worker/abstract-worker.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 }) } } -- 2.34.1