英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论