Skip to content

Commit

Permalink
fix: recover panic on storage init
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Sep 13, 2024
1 parent 1b42b96 commit 5d9167d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion internal/op/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package op

import (
"context"
"fmt"
"runtime"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5d9167d

Please sign in to comment.