From 1c01dc683931f9a71b5f2bd97ce78cc1eecda9ff Mon Sep 17 00:00:00 2001 From: Jason-Fly <869914918@qq.com> Date: Sat, 16 Nov 2024 13:20:49 +0800 Subject: [PATCH] fix(storage): delete storage fails if a panic occurred during initialization (#7501) * fix(storage): store storages map when init storage panic * fix(drivers): add nil check to drop method --- drivers/chaoxing/driver.go | 4 +++- drivers/vtencent/drive.go | 4 +++- internal/op/storage.go | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/chaoxing/driver.go b/drivers/chaoxing/driver.go index de122c36c4d..360c6e3d01d 100644 --- a/drivers/chaoxing/driver.go +++ b/drivers/chaoxing/driver.go @@ -67,7 +67,9 @@ func (d *ChaoXing) Init(ctx context.Context) error { } func (d *ChaoXing) Drop(ctx context.Context) error { - d.cron.Stop() + if d.cron != nil { + d.cron.Stop() + } return nil } diff --git a/drivers/vtencent/drive.go b/drivers/vtencent/drive.go index 676431439a9..36a9167234e 100644 --- a/drivers/vtencent/drive.go +++ b/drivers/vtencent/drive.go @@ -55,7 +55,9 @@ func (d *Vtencent) Init(ctx context.Context) error { } func (d *Vtencent) Drop(ctx context.Context) error { - d.cron.Stop() + if d.cron != nil { + d.cron.Stop() + } return nil } diff --git a/internal/op/storage.go b/internal/op/storage.go index 6790a8dffa6..7d8831f548e 100644 --- a/internal/op/storage.go +++ b/internal/op/storage.go @@ -101,7 +101,7 @@ func initStorage(ctx context.Context, storage model.Storage, storageDriver drive log.Errorf("panic init storage: %s", errInfo) driverStorage.SetStatus(errInfo) MustSaveDriverStorage(storageDriver) - storagesMap.Delete(driverStorage.MountPath) + storagesMap.Store(driverStorage.MountPath, storageDriver) } }() // Unmarshal Addition