Home  >  Article  >  Backend Development  >  Increase gRPC timeout in Go

Increase gRPC timeout in Go

WBOY
WBOYforward
2024-02-06 08:00:13560browse

增加 Go 中的 gRPC 超时

Question content

There are some gRPC calls that require the connection to stay connected for more than 5 minutes, and the connection will be idle until the operation is completed.

I tried keepalive settings and even context.WithTimeout() but the gRPC connection times out after 5 minutes (code = unknown desc = stream timeout")

How to increase the idle timeout for such gRPC calls?


Correct answer


Have you tried it

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

Similar to the definition in the official grpc documentation. This is the https://www.php.cn/link/491723c615d42eb8b44650bcbe384561 link.

The above is the detailed content of Increase gRPC timeout in Go. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete