Skip to content

Commit

Permalink
Fix race condition in transaction handling
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickTaibel committed Oct 6, 2023
1 parent 6620538 commit 8c6351f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ func (this *Client) FlushRedisAndRespond() (err error) {
if this.transactionDoneChannel != nil {
// If there was a transaction going on, we need to stop it, which will recycle the connection
close(this.transactionDoneChannel)
this.reservedRedisConn = nil
this.transactionDoneChannel = nil
} else {
// We are not in a transaction, so we can simply recycle it
connectionPool.RecycleRemoteConnection(redisConn)
Expand All @@ -201,6 +203,8 @@ func (this *Client) FlushRedisAndRespond() (err error) {
// Reset client and server connection as we can not recover from any error states
this.ReadChannel <- readItem{nil, err}
close(this.transactionDoneChannel)
this.reservedRedisConn = nil
this.transactionDoneChannel = nil
} else if this.reservedRedisConn == nil {
this.reservedRedisConn = redisConn
this.transactionDoneChannel = make(chan interface{}, 1)
Expand Down

0 comments on commit 8c6351f

Please sign in to comment.