Browse Source

Add Aurora errno to rejectReadOnly check (#634)

AWS Aurora returns a 1290 after failing over requiring the connection to
be closed and opened again to be able to perform writes.
Jeffrey Charles 8 years ago
parent
commit
e52f1902ca
3 changed files with 9 additions and 2 deletions
  1. 1 0
      AUTHORS
  2. 6 1
      README.md
  3. 2 1
      packets.go

+ 1 - 0
AUTHORS

@@ -34,6 +34,7 @@ INADA Naoki <songofacandy at gmail.com>
 Jacek Szwec <szwec.jacek at gmail.com>
 Jacek Szwec <szwec.jacek at gmail.com>
 James Harr <james.harr at gmail.com>
 James Harr <james.harr at gmail.com>
 Jeff Hodges <jeff at somethingsimilar.com>
 Jeff Hodges <jeff at somethingsimilar.com>
+Jeffrey Charles <jeffreycharles at gmail.com>
 Jian Zhen <zhenjl at gmail.com>
 Jian Zhen <zhenjl at gmail.com>
 Joshua Prunier <joshua.prunier at gmail.com>
 Joshua Prunier <joshua.prunier at gmail.com>
 Julien Lefevre <julien.lefevr at gmail.com>
 Julien Lefevre <julien.lefevr at gmail.com>

+ 6 - 1
README.md

@@ -279,7 +279,7 @@ Default:        false
 ```
 ```
 
 
 
 
-`rejectreadOnly=true` causes the driver to reject read-only connections. This
+`rejectReadOnly=true` causes the driver to reject read-only connections. This
 is for a possible race condition during an automatic failover, where the mysql
 is for a possible race condition during an automatic failover, where the mysql
 client gets connected to a read-only replica after the failover.
 client gets connected to a read-only replica after the failover.
 
 
@@ -294,6 +294,11 @@ If you are not relying on read-only transactions to reject writes that aren't
 supposed to happen, setting this on some MySQL providers (such as AWS Aurora)
 supposed to happen, setting this on some MySQL providers (such as AWS Aurora)
 is safer for failovers.
 is safer for failovers.
 
 
+Note that ERROR 1290 can be returned for a `read-only` server and this option will
+cause a retry for that error. However the same error number is used for some
+other cases. You should ensure your application will never cause an ERROR 1290
+except for `read-only` mode when enabling this option.
+
 
 
 ##### `timeout`
 ##### `timeout`
 
 

+ 2 - 1
packets.go

@@ -571,7 +571,8 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
 	errno := binary.LittleEndian.Uint16(data[1:3])
 	errno := binary.LittleEndian.Uint16(data[1:3])
 
 
 	// 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
 	// 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
-	if errno == 1792 && mc.cfg.RejectReadOnly {
+	// 1290: ER_OPTION_PREVENTS_STATEMENT (returned by Aurora during failover)
+	if (errno == 1792 || errno == 1290) && mc.cfg.RejectReadOnly {
 		// Oops; we are connected to a read-only connection, and won't be able
 		// Oops; we are connected to a read-only connection, and won't be able
 		// to issue any write statements. Since RejectReadOnly is configured,
 		// to issue any write statements. Since RejectReadOnly is configured,
 		// we throw away this connection hoping this one would have write
 		// we throw away this connection hoping this one would have write