kvdb: don't do a critical log for db serialization errors

In this commit, we fix a bug that would cause the entire db to shutdown
if hit a panic (since db operations in the main buckets exit with a
panic) while executing a txn call back. This might be a postgres error
we need to check, so we don't want to bail out, and instead want to pass
up the error to the caller so we can retry if needed.
This commit is contained in:
Olaoluwa Osuntokun 2023-09-19 18:15:38 -07:00 committed by Andras Banki-Horvath
parent 120d6dd297
commit cd0ca43a00
No known key found for this signature in database
GPG key ID: 80E5375C094198D8

View file

@ -170,8 +170,6 @@ func (db *db) getPrefixedTableName(table string) string {
func catchPanic(f func() error) (err error) {
defer func() {
if r := recover(); r != nil {
log.Criticalf("Caught unhandled error: %v", r)
switch data := r.(type) {
case error:
err = data
@ -179,6 +177,18 @@ func catchPanic(f func() error) (err error) {
default:
err = errors.New(fmt.Sprintf("%v", data))
}
// Before we issue a critical log which'll cause the
// daemon to shut down, we'll first check if this is a
// DB serialization error. If so, then we don't need to
// log as we can retry safely and avoid tearing
// everything down.
if sqldb.IsSerializationError(sqldb.MapSQLError(err)) {
log.Tracef("Detected db serialization error "+
"via panic: %v", err)
} else {
log.Criticalf("Caught unhandled error: %v", r)
}
}
}()