Fix SQLITE_BUSY retry logic
This commit is contained in:
parent
ce641a3ffe
commit
fbb9cf68ab
@ -81,6 +81,10 @@ func (j errorHTTPResponse) Headers() []string {
|
||||
return langext.ArrMap(j.headers, func(v headerval) string { return v.Key + "=" + v.Val })
|
||||
}
|
||||
|
||||
func (j errorHTTPResponse) Unwrap() error {
|
||||
return j.error
|
||||
}
|
||||
|
||||
func InternalError(e error) ginext.HTTPResponse {
|
||||
return createApiError(nil, "InternalError", 500, apierr.INTERNAL_EXCEPTION, 0, e.Error(), e)
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ require (
|
||||
github.com/jmoiron/sqlx v1.4.0
|
||||
github.com/mattn/go-sqlite3 v1.14.22
|
||||
github.com/rs/zerolog v1.33.0
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.512
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.513
|
||||
gopkg.in/loremipsum.v1 v1.1.2
|
||||
)
|
||||
|
||||
|
@ -118,6 +118,8 @@ gogs.mikescher.com/BlackForestBytes/goext v0.0.511 h1:vAEhXdexKlLTNf/mGHzemp/4rz
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.511/go.mod h1:9Q9EjraeE3yih7EXgBlnwLLJXWuRZNsl7s5TVTh3aOU=
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.512 h1:cdLUi1bSnGujtx8/K0fPql142aOvUyNPt+8aWMKKDFk=
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.512/go.mod h1:9Q9EjraeE3yih7EXgBlnwLLJXWuRZNsl7s5TVTh3aOU=
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.513 h1:zGb5n220AYNElzQs611RYXfZlnUw6/VJJesfLftphkQ=
|
||||
gogs.mikescher.com/BlackForestBytes/goext v0.0.513/go.mod h1:9Q9EjraeE3yih7EXgBlnwLLJXWuRZNsl7s5TVTh3aOU=
|
||||
golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8=
|
||||
golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
|
@ -9,9 +9,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/glebarez/go-sqlite"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"github.com/rs/zerolog/log"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/dataext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/exerr"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/ginext"
|
||||
"gogs.mikescher.com/BlackForestBytes/goext/langext"
|
||||
"math/rand"
|
||||
@ -229,12 +230,12 @@ func resetBody(g *gin.Context) error {
|
||||
|
||||
func isSqlite3Busy(r ginext.HTTPResponse) bool {
|
||||
if errwrap, ok := r.(interface{ Unwrap() error }); ok && errwrap != nil {
|
||||
{
|
||||
var s3err *sqlite.Error
|
||||
if errors.As(errwrap.Unwrap(), &s3err) {
|
||||
if s3err.Code() == 5 { // [5] == SQLITE_BUSY
|
||||
return true
|
||||
}
|
||||
orig := exerr.OriginalError(errwrap.Unwrap())
|
||||
|
||||
var sqlite3Err sqlite3.Error
|
||||
if errors.As(orig, &sqlite3Err) {
|
||||
if sqlite3Err.Code == 5 { // [5] == SQLITE_BUSY
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user