From: Jérôme Benoit Date: Fri, 22 Aug 2025 16:42:38 +0000 (+0200) Subject: refactor: make pool destroy() more robust X-Git-Tag: v5.1.4~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8b444c5b53ea4dcd204fe6b5f58db802ca4d88b2;p=poolifier.git refactor: make pool destroy() more robust Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index d074b72ed..cfd919ccf 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -617,20 +617,32 @@ export abstract class AbstractPool< throw new Error('Cannot destroy an already destroying pool') } this.destroying = true - await Promise.all( - this.workerNodes.map(async (_, workerNodeKey) => { - await this.destroyWorkerNode(workerNodeKey) - }) - ) - if (this.emitter != null) { - this.emitter.listenerCount(PoolEvents.destroy) > 0 && - this.emitter.emit(PoolEvents.destroy, this.info) - this.emitter.emitDestroy() - this.readyEventEmitted = false + try { + await Promise.allSettled( + this.workerNodes.map(async (_, workerNodeKey) => { + try { + await this.destroyWorkerNode(workerNodeKey) + } catch (error) { + if ( + this.emitter != null && + this.emitter.listenerCount(PoolEvents.error) > 0 + ) { + this.emitter.emit(PoolEvents.error, error) + } + } + }) + ) + } finally { + if (this.emitter != null) { + this.emitter.listenerCount(PoolEvents.destroy) > 0 && + this.emitter.emit(PoolEvents.destroy, this.info) + this.emitter.emitDestroy() + this.readyEventEmitted = false + } + delete this.startTimestamp + this.destroying = false + this.started = false } - delete this.startTimestamp - this.destroying = false - this.started = false } /** @inheritDoc */