on busy errors return bad conn to signal retry

This commit is contained in:
kim 2024-05-06 21:57:35 +01:00
parent 70d994f800
commit 0f486ebb59
1 changed files with 10 additions and 0 deletions

View File

@ -20,6 +20,7 @@
package sqlite
import (
"database/sql/driver"
"fmt"
"modernc.org/sqlite"
@ -42,6 +43,15 @@ func processSQLiteError(err error) error {
case sqlite3.SQLITE_CONSTRAINT_UNIQUE,
sqlite3.SQLITE_CONSTRAINT_PRIMARYKEY:
return db.ErrAlreadyExists
// Busy should be very rare, but
// on busy tell the database to close
// the connection, re-open and re-attempt
// which should give a necessary timeout.
case sqlite3.SQLITE_BUSY,
sqlite3.SQLITE_BUSY_RECOVERY,
sqlite3.SQLITE_BUSY_SNAPSHOT:
return driver.ErrBadConn
}
// Wrap the returned error with the code and