Skip to content

Commit 83d56b7

Browse files
authored
close connection explicitly before returning ErrBadConn for 1792 (#2)
1 parent 6b8624c commit 83d56b7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

packets.go

+10
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,16 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
553553

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

0 commit comments

Comments
 (0)