Comments (11)
How does something like Hikari handle validity checks?
from r2d2.
During validation Hikari temporarily changes the network timeout of the connection here.
from r2d2.
Similarly, during validation a PostgresConnectionManager
from r2d2-postgres could temporarily change the network timeout of its tls_connector
. I will check whether the underlying types expose the necessary functionality.
from r2d2.
I will check whether the underlying types expose the necessary functionality.
Unfortunately, they do not. In r2d2-postgres the MakeTlsConnect
wraps a tokio_postgres::Socket
, which wraps a tokio::net::TcpStream
, and neither has configurable timeouts.
from r2d2.
The Javadoc for Connection::setNetworkTimeout
is kind of interesting in that it discusses the timeout only applying to reads and not writes. I guess in practice the outbound TCP buffer doesn't fill for a single query?
postgres
could definitely grow support for read/write timeouts via tokio-postgres
, though it is interesting to note that libpq
does not offer that at all from what I can tell. I imagine they might just advise cranking the TCP keepalive interval down and relying on that.
from r2d2.
Thinking about this a bit more, it actually seems to me like TCP keepalive may be the better approach here compared to some kind of read/query timeout. It doesn't make assumptions about how long a query will legitimately take to run, and can detect a disconnect even while the connection is totally idle rather than only at the time of checkout.
from r2d2.
My understanding is TCP keepalives depend on three parameters:
- keepalive time, the amount of idle time before a keepalive
- keepalive interval, the amount of time after an unacknowledged keepalive before the next one
- keepalive probes, the number of unacknowledged keepalives before connection closure
tokio::net::TcpStream
exposes set_keepalive(duration)
, which sets the connection’s keepalive time to duration
. I think it does not allow configuration of keepalive interval and keepalive probes, whose UNIX defaults are 75 seconds and 9, which would still allow long timeouts.
An alternative is configuring the parameters at the machine level, but doing so could affect other services running on the machine, or the machine may be inaccessible.
I appreciate general read and write timeouts might introduce complexity and agree with your point about query time. Instead, what about limiting timeouts to validity checks that only make trivial queries? The Java interface exposes that functionality through isValid(timeout)
.
from r2d2.
We could definitely add a variant of is_valid that takes a timeout, but I'd want to be pretty careful about what timeouts are actually passed to it. For example, if get_timeout
is called with a 10 second timeout and we're 9.99995 seconds in when a connection becomes available, we probably wouldn't want to try calling is_valid with a 0.00005 second timeout, since that would almost assuredly fail.
from r2d2.
Sounds good! I think is_valid(timeout)
would ultimately require access to the Tokio runtime, so I will start with a pull request in the rust-postgres
repository.
from r2d2.
Now that Rust-Postgres exposes is_valid(timeout)
, I can think of two options that would maintain backward compatibility:
- Let
ManageConnection
implementations boundis_valid()
calls if they can or want. The bound would be independent oftimeout
inget_timeout(timeout)
. - Add a method
is_valid_timeout
to theManageConnection
trait that callsis_valid
by default. Then updateget_timeout
accordingly.
What do you think?
from r2d2.
I think adding ManageTimeout::is_valid_timeout
with a default impl seems best.
from r2d2.
Related Issues (20)
- roadmap to v1.0.0? HOT 3
- Will r2d2 create more connections than max_size when using builder()? HOT 3
- pool.get() returns Error(None) -- best debugging strategy? HOT 1
- Is there a way to not keep idle connections? HOT 8
- Can be used in the future such as tokio, async_std? HOT 1
- Use `compare_exchange` or `compare_exchange_weak` instead
- Is there a way to drop or close an actual connection when I'm using PooldConnection? HOT 4
- "Named" connections HOT 3
- Why example use `let pool = pool.clone()` in a for loop ? HOT 2
- Document relationship between `min_idle`, `idle_timeout` and `max_lifetime` HOT 1
- How to set timezone when linking HOT 1
- Release? HOT 1
- Allow hooking on connection get-from-pool and release-to-pool HOT 8
- Using behind proxychains HOT 1
- Seg fault with Postgres HOT 14
- Remove parking_lot dependency now that std's Mutex is faster than before HOT 3
- [Bug] CI test failure on arm HOT 4
- r2d2::Error should derive PartialEq and Clone HOT 4
- Pool building freezes when connections drop during initial setup HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from r2d2.