Skip to content

Commit

Permalink
close connection explicitly before returning ErrBadConn for 1792 (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
songgao authored May 29, 2017
1 parent 6b8624c commit 83d56b7
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,16 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {

// 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
if errno == 1792 && mc.cfg.RejectReadOnly {
// Oops; we are connected to a read-only connection, and won't be able
// to issue any write statements. Since RejectReadOnly is configured,
// we throw away this connection hoping this one would have write
// permission. This is specifically for an AWS Aurora behavior during
// failover. See README.md for more.
//
// We explicitly close the connection before returning
// driver.ErrBadConn to ensure that `database/sql` purges this
// connection and initiates a new one for next statement next time.
mc.Close()
return driver.ErrBadConn
}

Expand Down

0 comments on commit 83d56b7

Please sign in to comment.