-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
This method adds the ability to sets the number of maximum retries if the driver returns driver.ErrBadConn
Currently, database/sql has a hardcoded maxBadConnRetries, which is set to 2, and it will rerun the SQL if the driver returns a bad connection error, which is causing problems in many cases.
For example, if we have a long-running INSERT SQL, the first try might be killed due to TCP timeout or whatever reason, and the next retry will insert duplicated data, which is confusing to end-users.
With this option, we can set the max bad retry to 0, and write our retry logic to avoid the issue. and it also opens the opportunity to do some optimizations like https://cacm.acm.org/magazines/2013/2/160173-the-tail-at-scale/fulltext
Related issues:
Implementation:
I have tried to submit a possible implementation: https://go-review.googlesource.com/c/go/+/404935