Using timeouts
The timeout mechanism in YDB is designed to:
- Make sure the query execution time doesn’t exceed a certain interval after which its result is not interesting for further use.
Both of these use cases are important for ensuring the fault tolerance of the entire system. Let’s take a closer look at timeouts.
The value shows the time during which the query result is interesting to the user. If the operation fails during this time, the server returns an error with the Timeout
code and tries to terminate the query, but its cancellation is not guaranteed. So the query that the user was returned the error for can be both successfully executed on the server and canceled.
The client must set a transport timeout for each query. This value lets you determine the amount of time that the client is ready to wait for a response from the server. If the server doesn’t respond during this time, the client will get a transport error with the DeadlineExceeded
code. Be sure to set such a client timeout value that won’t trigger transport timeouts under the normal operation of the application and network.
We recommend that you always set an operation timeout and transport timeout. The value of the transport timeout should be 50-100 milliseconds more than that of the operation timeout, that way there is some time left for the client to get a server error with the code.
Timeout usage example:
C++
Go