From 34ac6fe986fb7d08dd8bcd28a808d0204ed87dde Mon Sep 17 00:00:00 2001 From: Vignesh Laxman <123447282+vlaxman-px@users.noreply.github.com> Date: Fri, 12 Jul 2024 12:17:13 +0530 Subject: [PATCH] PWX-33580 Run stat command with timeout during NFS Unmount (#2403) (#2459) * Made changes to run stat command with a timeout of 60 secondss * Change implementation using context as pexec is part of porx --------- Signed-off-by: Vignesh Laxman --- pkg/mount/mount.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 3facb35cf..6cc0095f6 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -4,12 +4,14 @@ package mount import ( + "context" "crypto/md5" "encoding/hex" "errors" "fmt" "io/ioutil" "os" + "os/exec" "path" "path/filepath" "regexp" @@ -102,6 +104,7 @@ const ( mountPathRemoveDelay = 30 * time.Second testDeviceEnv = "Test_Device_Mounter" bindMountPrefix = "readonly" + statTimeout = 30 * time.Second ) var ( @@ -725,7 +728,11 @@ func (m *Mounter) removeMountPath(path string) error { // RemoveMountPath makes the path writeable and removes it after a fixed delay func (m *Mounter) RemoveMountPath(mountPath string, opts map[string]string) error { - if _, err := os.Stat(mountPath); err == nil { + ctx, cancel := context.WithTimeout(context.Background(), statTimeout) + defer cancel() + cmd := exec.CommandContext(ctx, "stat", mountPath) + _, err := cmd.CombinedOutput() + if err == nil { if options.IsBoolOptionSet(opts, options.OptionsWaitBeforeDelete) { hasher := md5.New() hasher.Write([]byte(mountPath))