From f6d4953d4a7b3f9c5864fe943fd9f2f7fb4807a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Peliz=C3=A4us?= Date: Fri, 13 Oct 2023 16:55:08 +0200 Subject: [PATCH] lxd/storage/s3/miniod: Handle error from lock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Pelizäus --- lxd/storage/s3/miniod/miniod.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lxd/storage/s3/miniod/miniod.go b/lxd/storage/s3/miniod/miniod.go index bfb40efbe71d..1bc1200be78a 100644 --- a/lxd/storage/s3/miniod/miniod.go +++ b/lxd/storage/s3/miniod/miniod.go @@ -92,7 +92,11 @@ func (p *Process) Stop(ctx context.Context) error { return nil } - spawnUnlock := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, p.bucketName)) + spawnUnlock, err := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, p.bucketName)) + if err != nil { + return err + } + defer spawnUnlock() defer p.cancel.Cancel() @@ -161,7 +165,11 @@ func EnsureRunning(s *state.State, bucketVol storageDrivers.Volume) (*Process, e bucketName := bucketVol.Name() // Prevent concurrent spawning of same bucket. - spawnUnlock := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName)) + spawnUnlock, err := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName)) + if err != nil { + return nil, err + } + defer spawnUnlock() // Check if there is an existing running minio process for the bucket, and if so return it. @@ -346,9 +354,13 @@ func EnsureRunning(s *state.State, bucketVol storageDrivers.Volume) (*Process, e } // Get returns an existing MinIO process if it exists. -func Get(bucketName string) *Process { +func Get(bucketName string) (*Process, error) { // Wait for any ongoing spawn of the bucket process to finish. - spawnUnlock := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName)) + spawnUnlock, err := locking.Lock(context.TODO(), fmt.Sprintf("%s%s", minioLockPrefix, bucketName)) + if err != nil { + return nil, err + } + defer spawnUnlock() // Check if there is an existing running minio process for the bucket, and if so return it. @@ -361,10 +373,10 @@ func Get(bucketName string) *Process { minioProc.transactions++ minios[bucketName] = minioProc - return minioProc + return minioProc, nil } - return nil + return nil, nil } // StopAll stops all MinIO processes cleanly.