Description
What version of Go are you using (go version)?
jack@edi:~$ go version
go version go1.5beta3 linux/amd64
What operating system and processor architecture are you using?
jack@edi:~$ uname -a
Linux edi 3.13.0-61-generic #100-Ubuntu SMP Wed Jul 29 11:21:34 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
What did you do?
Execute a query with database/sql over an unreliable connection. For example:
update t set n=n+1;
What did you expect to see?
An error message that means the query failed and n is unchanged, or no error meaning the query executed exactly one time and n has been incremented by 1.
What did you see instead?
The query may have actually executed multiple times and thereby n may have been incremented multiple times.
Reproducing the error
It was necessary to build some infrastructure to reproduce this error. I wrote cavein, a TCP tunnel server that purposely breaks connections to aid in reproduction. That, combined with go_database_sql_retry_bug, a test application that executes many updates over the unreliable connections provided by cavein can reliably reproduce queries being executed extra times.
Suggested solution
Automatic retry should be removed from Exec and Query. It is impossible at the library layer to know if it is safe to retry a query.