From fbb9cf68abf4e5a10357417e1d5662995ea4a8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Mon, 16 Sep 2024 15:35:24 +0200 Subject: [PATCH] Fix SQLITE_BUSY retry logic --- scnserver/api/ginresp/resp.go | 4 ++++ scnserver/go.mod | 2 +- scnserver/go.sum | 2 ++ scnserver/logic/request.go | 15 ++++++++------- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/scnserver/api/ginresp/resp.go b/scnserver/api/ginresp/resp.go index 385ec4e..ba8aeb9 100644 --- a/scnserver/api/ginresp/resp.go +++ b/scnserver/api/ginresp/resp.go @@ -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) } diff --git a/scnserver/go.mod b/scnserver/go.mod index dc8daff..3d6387a 100644 --- a/scnserver/go.mod +++ b/scnserver/go.mod @@ -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 ) diff --git a/scnserver/go.sum b/scnserver/go.sum index 95245ba..a40e8c2 100644 --- a/scnserver/go.sum +++ b/scnserver/go.sum @@ -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= diff --git a/scnserver/logic/request.go b/scnserver/logic/request.go index f303b44..8ab2c14 100644 --- a/scnserver/logic/request.go +++ b/scnserver/logic/request.go @@ -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 } } }