sfackler / r2d2

A generic connection pool for Rust
Apache License 2.0
1.51k stars 82 forks source link

Add CustomizeConnection::on_release() #36

Closed Ereski closed 7 years ago

Ereski commented 7 years ago

CustomizeConnection::on_release() will be called with a connection before it is dropped. This can be useful for logging, benchmarking, or RDBMS-specific functionality, such as SQLite's PRAGMA optimize.

(note that I don't fully understand the utility of the DROPPED flag in test_connection_customizer(), so I'm not 100% sure the test is working as expected)

Ereski commented 7 years ago

Updated pull request with drop_conn (renamed drop_conns) taking a vector of connections to drop by value.

Ereski commented 7 years ago

This updated request has on_release() taking ownership of the connection, as you've been insisting. May I just point out that this allows the user to retain the connection indefinetly, or drop it when the internals lock guard is alive.

sfackler commented 7 years ago

I don't see why it would be a bad thing to let people hold onto old connections in the 0% chance they want to.

How does it allow the connection to be dropped while the lock is held? It seems pretty explicitly unlocked before the connection set is cleared.