diff --git a/pkg/azurefile-proxy/server/server.go b/pkg/azurefile-proxy/server/server.go index 3a7e33f30a..c8221a3e1f 100644 --- a/pkg/azurefile-proxy/server/server.go +++ b/pkg/azurefile-proxy/server/server.go @@ -21,12 +21,15 @@ import ( "fmt" "net" "strings" + "time" grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus" "google.golang.org/grpc" "k8s.io/klog/v2" mount_utils "k8s.io/mount-utils" + "sigs.k8s.io/azurefile-csi-driver/pkg/azurefile" mount_azurefile "sigs.k8s.io/azurefile-csi-driver/pkg/azurefile-proxy/pb" + volumehelper "sigs.k8s.io/azurefile-csi-driver/pkg/util" ) type MountServer struct { @@ -55,8 +58,16 @@ func (server *MountServer) MountAzureFile(_ context.Context, sensitiveOptions := req.GetSensitiveOptions() klog.V(2).Infof("received mount request: source: %s, target: %s, fstype: %s, options: %s", source, target, fstype, strings.Join(options, ",")) - err = server.mounter.MountSensitive(source, target, fstype, options, sensitiveOptions) - if err != nil { + execFunc := func() error { + return server.mounter.MountSensitive(source, target, fstype, options, sensitiveOptions) + } + + mountTimeoutInSec := azurefile.MountTimeoutInSec - 2 + timeoutFunc := func() error { + return fmt.Errorf("mount operation timed out after %d seconds: source=%s, target=%s", mountTimeoutInSec, source, target) + } + + if err = volumehelper.WaitUntilTimeout(time.Duration(mountTimeoutInSec)*time.Second, execFunc, timeoutFunc); err != nil { klog.Error("azurefile mount failed: with error:", err.Error()) return nil, fmt.Errorf("azurefile mount failed: %v", err) } diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go index 0c7e02bc17..f4fe9faf4b 100644 --- a/pkg/azurefile/azurefile.go +++ b/pkg/azurefile/azurefile.go @@ -212,6 +212,8 @@ const ( standardv2 = "standardv2" premiumv2 = "premiumv2" + + MountTimeoutInSec = 90 ) var ( diff --git a/pkg/azurefile/nodeserver.go b/pkg/azurefile/nodeserver.go index fd43ec6e4b..3721969616 100644 --- a/pkg/azurefile/nodeserver.go +++ b/pkg/azurefile/nodeserver.go @@ -458,8 +458,10 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe execFunc := func() error { return SMBMount(d.mounter, source, cifsMountPath, mountFsType, mountOptions, sensitiveMountOptions) } - timeoutFunc := func() error { return fmt.Errorf("time out") } - if err := volumehelper.WaitUntilTimeout(90*time.Second, execFunc, timeoutFunc); err != nil { + timeoutFunc := func() error { + return fmt.Errorf("mount operation timed out after %d seconds: source=%s, target=%s", MountTimeoutInSec, source, cifsMountPath) + } + if err := volumehelper.WaitUntilTimeout(MountTimeoutInSec*time.Second, execFunc, timeoutFunc); err != nil { var helpLinkMsg string if d.appendMountErrorHelpLink { helpLinkMsg = "\nPlease refer to http://aka.ms/filemounterror for possible causes and solutions for mount errors." @@ -772,7 +774,6 @@ func (d *Driver) mountWithProxy(ctx context.Context, source, target, fsType stri klog.Error("failed to close connection to azurefile proxy:", err) } }() - klog.V(2).Infof("connected to azurefile proxy successfully") mountClient := NewMountClient(conn) mountreq := mount_azurefile.MountAzureFileRequest{ @@ -783,12 +784,19 @@ func (d *Driver) mountWithProxy(ctx context.Context, source, target, fsType stri SensitiveOptions: sensitiveMountOptions, } klog.V(2).Infof("begin to mount with azurefile proxy, source: %s, target: %s, fstype: %s, mountOptions: %v", source, target, fsType, options) - _, err = mountClient.service.MountAzureFile(ctx, &mountreq) - if err != nil { - klog.Error("GRPC call returned with an error:", err) + newCtx, cancel := context.WithTimeout(ctx, MountTimeoutInSec*time.Second) + defer cancel() + execFunc := func() error { + _, err := mountClient.service.MountAzureFile(newCtx, &mountreq) return err } + timeoutFunc := func() error { + return fmt.Errorf("mount with azurefile proxy timed out after %d seconds: source=%s, target=%s", MountTimeoutInSec, source, target) + } + if err = volumehelper.WaitUntilTimeout(MountTimeoutInSec*time.Second, execFunc, timeoutFunc); err != nil { + klog.Error("GRPC call returned with an error:", err) + } return err }