fix: close communication channel on error
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 20 Jul 2023 16:10:45 +0000 (18:10 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 20 Jul 2023 16:10:45 +0000 (18:10 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts

index 93023794ceb8f27519fc73e4c3e79c73efb21338..d55c3101bcaead44cab1b424a170383165dc52be 100644 (file)
@@ -862,6 +862,7 @@ export abstract class AbstractPool<
       const workerNodeKey = this.getWorkerNodeKey(worker)
       const workerInfo = this.getWorkerInfo(workerNodeKey)
       workerInfo.ready = false
+      this.workerNodes[workerNodeKey].closeChannel()
       this.emitter?.emit(PoolEvents.error, error)
       if (this.opts.restartWorkerOnError === true && !this.starting) {
         if (workerInfo.dynamic) {
@@ -877,7 +878,6 @@ export abstract class AbstractPool<
     worker.on('online', this.opts.onlineHandler ?? EMPTY_FUNCTION)
     worker.on('exit', this.opts.exitHandler ?? EMPTY_FUNCTION)
     worker.once('exit', () => {
-      this.workerNodes[this.getWorkerNodeKey(worker)].closeChannel()
       this.removeWorkerNode(worker)
     })