From 8b444c5b53ea4dcd204fe6b5f58db802ca4d88b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 22 Aug 2025 18:42:38 +0200 Subject: [PATCH] refactor: make pool destroy() more robust MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) 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 */ -- 2.43.0