Skip to content

Commit e52f190

Browse files
jeffcharlesjulienschmidt
authored andcommitted
Add Aurora errno to rejectReadOnly check (go-sql-driver#634)
AWS Aurora returns a 1290 after failing over requiring the connection to be closed and opened again to be able to perform writes.
1 parent c6c4e3c commit e52f190

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ INADA Naoki <songofacandy at gmail.com>
3434
Jacek Szwec <szwec.jacek at gmail.com>
3535
James Harr <james.harr at gmail.com>
3636
Jeff Hodges <jeff at somethingsimilar.com>
37+
Jeffrey Charles <jeffreycharles at gmail.com>
3738
Jian Zhen <zhenjl at gmail.com>
3839
Joshua Prunier <joshua.prunier at gmail.com>
3940
Julien Lefevre <julien.lefevr at gmail.com>

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ Default: false
279279
```
280280

281281

282-
`rejectreadOnly=true` causes the driver to reject read-only connections. This
282+
`rejectReadOnly=true` causes the driver to reject read-only connections. This
283283
is for a possible race condition during an automatic failover, where the mysql
284284
client gets connected to a read-only replica after the failover.
285285

@@ -294,6 +294,11 @@ If you are not relying on read-only transactions to reject writes that aren't
294294
supposed to happen, setting this on some MySQL providers (such as AWS Aurora)
295295
is safer for failovers.
296296

297+
Note that ERROR 1290 can be returned for a `read-only` server and this option will
298+
cause a retry for that error. However the same error number is used for some
299+
other cases. You should ensure your application will never cause an ERROR 1290
300+
except for `read-only` mode when enabling this option.
301+
297302

298303
##### `timeout`
299304

packets.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
571571
errno := binary.LittleEndian.Uint16(data[1:3])
572572

573573
// 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
574-
if errno == 1792 && mc.cfg.RejectReadOnly {
574+
// 1290: ER_OPTION_PREVENTS_STATEMENT (returned by Aurora during failover)
575+
if (errno == 1792 || errno == 1290) && mc.cfg.RejectReadOnly {
575576
// Oops; we are connected to a read-only connection, and won't be able
576577
// to issue any write statements. Since RejectReadOnly is configured,
577578
// we throw away this connection hoping this one would have write

0 commit comments

Comments
 (0)