Skip to content

Commit 4736a58

Browse files
authored
Merge pull request kubernetes-sigs#2921 from k8s-infra-cherrypick-robot/cherry-pick-2916-to-release-1.33
[release-1.33] fix: add mount timeout in NFS EiT mount
2 parents 38ad203 + 5677040 commit 4736a58

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

pkg/azurefile-proxy/server/server.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ import (
2121
"fmt"
2222
"net"
2323
"strings"
24+
"time"
2425

2526
grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
2627
"google.golang.org/grpc"
2728
"k8s.io/klog/v2"
2829
mount_utils "k8s.io/mount-utils"
30+
"sigs.k8s.io/azurefile-csi-driver/pkg/azurefile"
2931
mount_azurefile "sigs.k8s.io/azurefile-csi-driver/pkg/azurefile-proxy/pb"
32+
volumehelper "sigs.k8s.io/azurefile-csi-driver/pkg/util"
3033
)
3134

3235
type MountServer struct {
@@ -55,8 +58,16 @@ func (server *MountServer) MountAzureFile(_ context.Context,
5558
sensitiveOptions := req.GetSensitiveOptions()
5659
klog.V(2).Infof("received mount request: source: %s, target: %s, fstype: %s, options: %s", source, target, fstype, strings.Join(options, ","))
5760

58-
err = server.mounter.MountSensitive(source, target, fstype, options, sensitiveOptions)
59-
if err != nil {
61+
execFunc := func() error {
62+
return server.mounter.MountSensitive(source, target, fstype, options, sensitiveOptions)
63+
}
64+
65+
mountTimeoutInSec := azurefile.MountTimeoutInSec - 2
66+
timeoutFunc := func() error {
67+
return fmt.Errorf("mount operation timed out after %d seconds: source=%s, target=%s", mountTimeoutInSec, source, target)
68+
}
69+
70+
if err = volumehelper.WaitUntilTimeout(time.Duration(mountTimeoutInSec)*time.Second, execFunc, timeoutFunc); err != nil {
6071
klog.Error("azurefile mount failed: with error:", err.Error())
6172
return nil, fmt.Errorf("azurefile mount failed: %v", err)
6273
}

pkg/azurefile/azurefile.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ const (
212212

213213
standardv2 = "standardv2"
214214
premiumv2 = "premiumv2"
215+
216+
MountTimeoutInSec = 90
215217
)
216218

217219
var (

pkg/azurefile/nodeserver.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -458,8 +458,10 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
458458
execFunc := func() error {
459459
return SMBMount(d.mounter, source, cifsMountPath, mountFsType, mountOptions, sensitiveMountOptions)
460460
}
461-
timeoutFunc := func() error { return fmt.Errorf("time out") }
462-
if err := volumehelper.WaitUntilTimeout(90*time.Second, execFunc, timeoutFunc); err != nil {
461+
timeoutFunc := func() error {
462+
return fmt.Errorf("mount operation timed out after %d seconds: source=%s, target=%s", MountTimeoutInSec, source, cifsMountPath)
463+
}
464+
if err := volumehelper.WaitUntilTimeout(MountTimeoutInSec*time.Second, execFunc, timeoutFunc); err != nil {
463465
var helpLinkMsg string
464466
if d.appendMountErrorHelpLink {
465467
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
772774
klog.Error("failed to close connection to azurefile proxy:", err)
773775
}
774776
}()
775-
klog.V(2).Infof("connected to azurefile proxy successfully")
776777

777778
mountClient := NewMountClient(conn)
778779
mountreq := mount_azurefile.MountAzureFileRequest{
@@ -783,12 +784,19 @@ func (d *Driver) mountWithProxy(ctx context.Context, source, target, fsType stri
783784
SensitiveOptions: sensitiveMountOptions,
784785
}
785786
klog.V(2).Infof("begin to mount with azurefile proxy, source: %s, target: %s, fstype: %s, mountOptions: %v", source, target, fsType, options)
786-
_, err = mountClient.service.MountAzureFile(ctx, &mountreq)
787-
if err != nil {
788-
klog.Error("GRPC call returned with an error:", err)
787+
newCtx, cancel := context.WithTimeout(ctx, MountTimeoutInSec*time.Second)
788+
defer cancel()
789+
execFunc := func() error {
790+
_, err := mountClient.service.MountAzureFile(newCtx, &mountreq)
789791
return err
790792
}
793+
timeoutFunc := func() error {
794+
return fmt.Errorf("mount with azurefile proxy timed out after %d seconds: source=%s, target=%s", MountTimeoutInSec, source, target)
795+
}
791796

797+
if err = volumehelper.WaitUntilTimeout(MountTimeoutInSec*time.Second, execFunc, timeoutFunc); err != nil {
798+
klog.Error("GRPC call returned with an error:", err)
799+
}
792800
return err
793801
}
794802

0 commit comments

Comments
 (0)