Skip to content

Commit c2c9ce2

Browse files
authored
Merge pull request #2481 from ardentperf/pr-txstatus-check
stdlib: Discard connections with open transactions in ResetSession
2 parents 3a19891 + efcd550 commit c2c9ce2

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

stdlib/sql.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,12 @@ func (c *Conn) ResetSession(ctx context.Context) error {
555555
return driver.ErrBadConn
556556
}
557557

558+
// Discard connection if it has an open transaction. This can happen if the
559+
// application did not properly commit or rollback a transaction.
560+
if c.conn.PgConn().TxStatus() != 'I' {
561+
return driver.ErrBadConn
562+
}
563+
558564
now := time.Now()
559565
idle := now.Sub(c.lastResetSessionTime)
560566

0 commit comments

Comments
 (0)