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) { |
3,053✔ |
|
for retry := 0; retry < 50; retry++ { |
6,255✔ |
|
if result, err = f(); err == nil { |
6,233✔ |
|
return
|
3,031✔ |
|
} |
3,031✔ |
13 |
|
|
|
switch err {
|
171✔ |
|
case sql.ErrConnDone:
|
× |
16 |
|
|
|
case sql.ErrTxDone, sql.ErrNoRows:
|
6✔ |
|
return
|
6✔ |
19 |
|
|
|
default:
|
165✔ |
|
if isErrBadConn(err) || IsDeadlock(err) {
|
314✔ |
|
time.Sleep(5 * time.Millisecond)
|
149✔ |
|
} else {
|
165✔ |
|
return
|
16✔ |
|
} |
16✔ |
26 |
} |
|
27 |
} |
|
28 |
|
|
|
if err == sql.ErrConnDone || isErrBadConn(err) {
|
× |
|
reportError(query, err) |
× |
|
} |
× |
32 |
|
|
|
return
|
× |
34 |
} |