When you use a gRPC it is a very important to set deadlines.
In gRPC, deadlines are absolute timestamps that tell our system when the response of an RPC call is
no longer needed. The deadline is sent to the server, and the computation is automatically interrupted
when the deadline is exceeded. The client call automatically ends with a
When you don't specify a deadline, client requests never timeout. All in-flight requests take resources on the server, and possibly upstream servers, which can ultimately hurt latency or crash the entire process.
In ZIO gRPC you can easily set deadlines (absolute timestamps), or timeouts which are relative to the time the outbound call is made.
To set the same timeout for all requests, it is possible to provide an effect that produces
when constructing the client. This effect is invoked before each request, and can determine the deadline
relative to the system clock at the time the effect is executed.
As in the previous example, assuming there is a client in the environment, we can set the timeout for each request like this:
Clients provide (through the
CallOptionsMethods trait) a number of methods that make it possible
to specify a deadline or a timeout for each request:
If you are using a client instance, the above methods are available to provide you with a new
client that has a modified
CallOptions effect. Making the copy of those clients is cheap and can
be safely done for each individual call: