Skip to content

Commit

Permalink
grpc-proxy: use long timeout for proxy clients
Browse files Browse the repository at this point in the history
Replace client context timeout with
GRPCServiceLongTimeout * 2 where engine binary
executed without timeout.

Longhorn-4096

Signed-off-by: Chin-Ya Huang <chin-ya.huang@suse.com>
  • Loading branch information
c3y1huang authored and shuo-wu committed Jun 9, 2022
1 parent a304db6 commit 718a305
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pkg/client/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"github.com/longhorn/longhorn-instance-manager/pkg/meta"
"github.com/longhorn/longhorn-instance-manager/pkg/util"

eclient "github.com/longhorn/longhorn-engine/pkg/controller/client"
emeta "github.com/longhorn/longhorn-engine/pkg/meta"
eclient "github.com/longhorn/longhorn-engine/pkg/replica/client"
)

var (
Expand Down Expand Up @@ -96,14 +96,20 @@ func NewProxyClient(ctx context.Context, ctxCancel context.CancelFunc, address s
}

const (
GRPCServiceTimeout = eclient.GRPCServiceTimeout * 2
GRPCServiceTimeout = eclient.GRPCServiceCommonTimeout * 2
GRPCServiceLongTimeout = eclient.GRPCServiceLongTimeout + GRPCServiceTimeout
)

func getContextWithGRPCTimeout(parent context.Context) context.Context {
ctx, _ := context.WithTimeout(parent, GRPCServiceTimeout)
return ctx
}

func getContextWithGRPCLongTimeout(parent context.Context) context.Context {
ctx, _ := context.WithTimeout(parent, GRPCServiceLongTimeout)
return ctx
}

func (c *ProxyClient) getProxyErrorPrefix(destination string) string {
return fmt.Sprintf("proxyServer=%v destination=%v:", c.ServiceURL, destination)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/proxy_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *ProxyClient) ReplicaAdd(serviceAddress, replicaAddress string, restore
ReplicaAddress: replicaAddress,
Restore: restore,
}
_, err = c.service.ReplicaAdd(getContextWithGRPCTimeout(c.ctx), req)
_, err = c.service.ReplicaAdd(getContextWithGRPCLongTimeout(c.ctx), req)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/proxy_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c *ProxyClient) SnapshotClone(serviceAddress, name, fromController string)
SnapshotName: name,
ExportBackingImageIfExist: false,
}
_, err = c.service.SnapshotClone(getContextWithGRPCTimeout(c.ctx), req)
_, err = c.service.SnapshotClone(getContextWithGRPCLongTimeout(c.ctx), req)
if err != nil {
return err
}
Expand Down

0 comments on commit 718a305

Please sign in to comment.