From 87768d07bb21fc3f8b7da818d5aaa0b77ff714a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Bebr=C4=ABtis?= Date: Wed, 11 Sep 2024 11:31:34 +0300 Subject: [PATCH] Map context concurrency fix --- VERSION | 2 +- pkg/rclone/nodeserver.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1c5ae58..5e008de 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v3.0.0 \ No newline at end of file +v3.0.1 \ No newline at end of file diff --git a/pkg/rclone/nodeserver.go b/pkg/rclone/nodeserver.go index 09baefe..fc06a79 100644 --- a/pkg/rclone/nodeserver.go +++ b/pkg/rclone/nodeserver.go @@ -10,6 +10,7 @@ import ( "os/exec" "strconv" "strings" + "sync" "time" v1 "k8s.io/api/core/v1" @@ -36,9 +37,12 @@ type nodeServer struct { *csicommon.DefaultNodeServer mounter *mount.SafeFormatAndMount mountContext map[string]*mountContext + mu sync.RWMutex } func (ns *nodeServer) getMountContext(targetPath string) *mountContext { + ns.mu.RLock() + defer ns.mu.RUnlock() if mc, ok := ns.mountContext[targetPath]; ok { return mc } @@ -46,6 +50,8 @@ func (ns *nodeServer) getMountContext(targetPath string) *mountContext { } func (ns *nodeServer) setMountContext(targetPath string, mc *mountContext) { + ns.mu.Lock() + defer ns.mu.Unlock() // create a new mount context if ns.mountContext == nil { ns.mountContext = make(map[string]*mountContext) @@ -54,6 +60,8 @@ func (ns *nodeServer) setMountContext(targetPath string, mc *mountContext) { } func (ns *nodeServer) deleteMountContext(targetPath string) { + ns.mu.Lock() + defer ns.mu.Unlock() delete(ns.mountContext, targetPath) }