khonsulabs / bonsaidb

A developer-friendly document database that grows with you, written in Rust
https://bonsaidb.io/
Apache License 2.0
1.03k stars 37 forks source link

Client should have configurable timeout options #297

Closed ecton closed 1 year ago

ecton commented 1 year ago

Before BonsaiDb supported its blocking APIs, there was a way to cancel requests: use tokio::timeout. However, that isn't very ergonomic, and now that there is a blocking API, there is no way to ensure that an API request doesn't hang for a very long time.

The Client should have at least two timeout settings:

Normally I would argue for an idle timeout, but #116 will address idle connections.

Because different code may want different timeout configurations, the request timeout setting should be modifiable on each Client instance. Because the connection task is shared between all Client instances, the connect timeout can only be set on the client builder.

One thing we should consider: if a request times out, should we try to send a request cancellation to the server? The server's current request processing may make it tricky to support cancellation of tasks, but it might be something to consider to help for a situation where the reason requests are timing out is because of a server being overloaded.

Thank you @phantie in #296 for reporting this deficiency!