Skip to content

Commit 0cd70c4

Browse files
committed
fix: add lock in CreateVolume to avoid race condition
1 parent f8acafd commit 0cd70c4

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pkg/smb/controllerserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
9999
}
100100
}
101101

102+
if acquired := d.volumeLocks.TryAcquire(name); !acquired {
103+
return nil, status.Errorf(codes.Aborted, volumeOperationAlreadyExistsFmt, name)
104+
}
105+
defer d.volumeLocks.Release(name)
106+
102107
if createSubDir {
103108
// Mount smb base share so we can create a subdirectory
104109
if err := d.internalMount(ctx, smbVol, volCap, secrets); err != nil {

0 commit comments

Comments
 (0)