From 6e7ad1daa5b18dc3e6b44884de27eb46f7b49ab9 Mon Sep 17 00:00:00 2001 From: weizhichen Date: Thu, 17 Apr 2025 04:32:42 +0000 Subject: [PATCH] fix: grpc connection was not closed properly --- pkg/blob/nodeserver.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/pkg/blob/nodeserver.go b/pkg/blob/nodeserver.go index a5d9414b9..f1b5f7a80 100644 --- a/pkg/blob/nodeserver.go +++ b/pkg/blob/nodeserver.go @@ -165,20 +165,29 @@ func (d *Driver) mountBlobfuseWithProxy(args, protocol string, authEnv []string) defer cancel() klog.V(2).Infof("start connecting to blobfuse proxy, protocol: %s, args: %s", protocol, args) conn, err := grpc.DialContext(ctx, d.blobfuseProxyEndpoint, grpc.WithInsecure(), grpc.WithBlock()) - if err == nil { - mountClient := NewMountClient(conn) - mountreq := mount_azure_blob.MountAzureBlobRequest{ - MountArgs: args, - Protocol: protocol, - AuthEnv: authEnv, - } - klog.V(2).Infof("begin to mount with blobfuse proxy, protocol: %s, args: %s", protocol, args) - resp, err = mountClient.service.MountAzureBlob(context.TODO(), &mountreq) - if err != nil { - klog.Error("GRPC call returned with an error:", err) + if err != nil { + klog.Errorf("failed to connect to blobfuse proxy: %v", err) + return "", err + } + defer func() { + if err := conn.Close(); err != nil { + klog.Errorf("failed to close connection to blobfuse proxy: %v", err) } - output = resp.GetOutput() + }() + + mountClient := NewMountClient(conn) + mountreq := mount_azure_blob.MountAzureBlobRequest{ + MountArgs: args, + Protocol: protocol, + AuthEnv: authEnv, + } + klog.V(2).Infof("begin to mount with blobfuse proxy, protocol: %s, args: %s", protocol, args) + resp, err = mountClient.service.MountAzureBlob(context.TODO(), &mountreq) + if err != nil { + klog.Error("GRPC call returned with an error:", err) } + output = resp.GetOutput() + return output, err }