mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 06:21:40 +01:00
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:
parent
120d6dd297
commit
cd0ca43a00
1 changed files with 12 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue