From aa0a573d3cd710d3f4c3f0fd52ed7536a81a0f1a Mon Sep 17 00:00:00 2001 From: Harminder Virk Date: Thu, 25 Jul 2024 10:13:05 +0530 Subject: [PATCH] fix: cleanup of resources when using replicas Closes: #1045 --- src/connection/index.ts | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/src/connection/index.ts b/src/connection/index.ts index 37eee0f1..c63f24ac 100644 --- a/src/connection/index.ts +++ b/src/connection/index.ts @@ -105,16 +105,6 @@ export class Connection extends EventEmitter implements ConnectionContract { } } - /** - * Cleanup references - */ - private cleanup(): void { - this.client = undefined - this.readClient = undefined - this.readReplicas = [] - this.roundRobinCounter = 0 - } - /** * Does cleanup by removing knex reference and removing all listeners. * For the same of simplicity, we get rid of both read and write @@ -127,7 +117,7 @@ export class Connection extends EventEmitter implements ConnectionContract { */ this.pool!.on('poolDestroySuccess', () => { this.logger.trace({ connection: this.name }, 'pool destroyed, cleaning up resource') - this.cleanup() + this.client = undefined this.emit('disconnect', this) this.removeAllListeners() }) @@ -135,7 +125,9 @@ export class Connection extends EventEmitter implements ConnectionContract { if (this.readPool !== this.pool) { this.readPool!.on('poolDestroySuccess', () => { this.logger.trace({ connection: this.name }, 'pool destroyed, cleaning up resource') - this.cleanup() + this.roundRobinCounter = 0 + this.readClient = undefined + this.readReplicas = [] this.emit('disconnect', this) this.removeAllListeners() })