1 |
package mssqlx
|
|
2 |
|
|
3 |
import (
|
|
4 |
"database/sql"
|
|
5 |
"time"
|
|
6 |
) |
|
7 |
|
|
|
func retryFunc(query string, f func() (interface{}, error)) (result interface{}, err error) { |
5,053✔ |
|
for retry := 0; retry < 50; retry++ { |
10,370✔ |
|
if result, err = f(); err == nil { |
10,351✔ |
|
return
|
5,034✔ |
|
} |
5,034✔ |
13 |
|
|
|
switch err {
|
283✔ |
|
case sql.ErrConnDone:
|
× |
16 |
|
|
|
case sql.ErrTxDone, sql.ErrNoRows:
|
3✔ |
|
return
|
3✔ |
19 |
|
|
|
default:
|
280✔ |
|
if isErrBadConn(err) || IsDeadlock(err) {
|
544✔ |
|
time.Sleep(5 * time.Millisecond)
|
264✔ |
|
} else {
|
280✔ |
|
return
|
16✔ |
|
} |
16✔ |
26 |
} |
|
27 |
} |
|
28 |
|
|
|
if err == sql.ErrConnDone || isErrBadConn(err) {
|
× |
|
reportError(query, err) |
× |
|
} |
× |
32 |
|
|
|
return
|
× |
34 |
} |