Timeout
The timeout pattern prevents remote procedure calls from waiting indefinitely for a response. A timeout specifies how long the RPC has to return. If there is no response by the timeout, the RPC invokes a fallback mechanism, whether it’s retrying the request, throwing an exception, or something else. This pattern is perhaps the most basic, fundamental resilience pattern used in RPCs.
You can use to set servers' readTimeout
and .
Client
There are two methods to set timeout for client.
One is set read/write deadline for connections and another is using context.Context
.
sets the ConnectTimeout to 10 seconds but has not set ReadTimeout and WriteTimeout. If the timeout has not been set, there is no timeout for accessing.
context.Context
context.Context
since Go 1.7 can be used to control timeout.
By smallnest updated 2018-12-04 11:47:26