Skip to content

Commit

Permalink
fix: cleanup of resources when using replicas
Browse files Browse the repository at this point in the history
Closes: #1045
  • Loading branch information
thetutlage committed Jul 25, 2024
1 parent 2aee01a commit aa0a573
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/connection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -127,15 +117,17 @@ 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()
})

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()
})
Expand Down

0 comments on commit aa0a573

Please sign in to comment.