Skip to content

Commit ee46028

Browse files
jeffcharlesBrigitte Lamarche
authored and
Brigitte Lamarche
committed
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 5eaa5ff commit ee46028

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
@@ -35,6 +35,7 @@ INADA Naoki <songofacandy at gmail.com>
3535
Jacek Szwec <szwec.jacek at gmail.com>
3636
James Harr <james.harr at gmail.com>
3737
Jeff Hodges <jeff at somethingsimilar.com>
38+
Jeffrey Charles <jeffreycharles at gmail.com>
3839
Jian Zhen <zhenjl at gmail.com>
3940
Joshua Prunier <joshua.prunier at gmail.com>
4041
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
@@ -580,7 +580,8 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
580580
errno := binary.LittleEndian.Uint16(data[1:3])
581581

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

0 commit comments

Comments
 (0)