For grpc.ConnectionTimeout()
, the Go GRPC docs mention:
ConnectionTimeout returns a ServerOption that sets the timeout for connection establishment (up to and including HTTP/2 handshaking) for all new connections. If this is not set, the default is 120 seconds.
Meanwhile, the docs about context.WithTimeout()
say:
WithTimeout returns WithDeadline(parent, time.Now().Add(timeout)).
Canceling this context releases resources associated with it, so code should call cancel as soon as the operations running in this Context complete
What I’m trying to do is configure timeouts on every GRPC request that hits a server, and wondering if grpc.ConnectionTimeout()
or context.WithTimeout()
is more appropriate.
Ideally, I want to configure a universal timeout for all requests of say, 5 seconds, and configure a smaller timeout of 100ms on requests that hit a specific path. How can I do this using either (or both) ConnectionTimeout()
and context.WithTimeout()
?