在Go中增加gRPC超时时间

huangapple go评论96阅读模式
英文:

Increase gRPC timeout in Go

问题

有一些 gRPC 调用需要保持连接超过 5 分钟,直到操作完成之前都会处于空闲状态。我尝试了 keepalive 设置和 context.WithTimeout(),但是 gRPC 连接在 5 分钟后超时了(错误代码为 Unknown desc = stream timeout)。

我该如何增加这些 gRPC 调用的空闲超时时间?

英文:

There are a few gRPC calls that require the connection to remain connected for more than 5 minutes, which will be idle till the operation is complete.
I tried keepalive settings and even context.WithTimeout() but the gRPC connection gets timed out ater 5 minutes (code = Unknown desc = stream timeout")

How can i increase the idle timeout for such gRPC calls?

答案1

得分: 2

你是否尝试过以下代码片段,如gRPC官方文档中所定义的:

clientDeadline := time.Now().Add(time.Duration(*deadlineMs) * time.Millisecond)
ctx, cancel := context.WithDeadline(ctx, clientDeadline)

这是在https://grpc.io/blog/deadlines/链接中提到的。

英文:

Have you tried,

clientDeadline := time.Now().Add(time.Duration(*deadlineMs) * time.Millisecond)
ctx, cancel := context.WithDeadline(ctx, clientDeadline)

like defined in official documentation of gRPC. Here is the https://grpc.io/blog/deadlines/ link.

huangapple
  • 本文由 发表于 2023年6月20日 17:47:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76513424.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定