fix: recover panic on storage init

pull/7196/head
Andy Hsu 2024-09-13 23:50:51 +08:00
parent 1b42b9627c
commit 5d9167d676
1 changed files with 17 additions and 1 deletions

View File

@ -2,6 +2,8 @@ package op
import (
"context"
"fmt"
"runtime"
"sort"
"strings"
"time"
@ -83,11 +85,25 @@ func LoadStorage(ctx context.Context, storage model.Storage) error {
return err
}
func getCurrentGoroutineStack() string {
buf := make([]byte, 1<<16)
n := runtime.Stack(buf, false)
return string(buf[:n])
}
// initStorage initialize the driver and store to storagesMap
func initStorage(ctx context.Context, storage model.Storage, storageDriver driver.Driver) (err error) {
storageDriver.SetStorage(storage)
driverStorage := storageDriver.GetStorage()
defer func() {
if err := recover(); err != nil {
errInfo := fmt.Sprintf("[panic] err: %v\nstack: %s\n", err, getCurrentGoroutineStack())
log.Errorf("panic init storage: %s", errInfo)
driverStorage.SetStatus(errInfo)
MustSaveDriverStorage(storageDriver)
storagesMap.Delete(driverStorage.MountPath)
}
}()
// Unmarshal Addition
err = utils.Json.UnmarshalFromString(driverStorage.Addition, storageDriver.GetAddition())
if err == nil {