Closed jutbin closed 2 months ago
The default RecyclingMethod is Fast which doesn't perform any check of the underlying connection object. It's quite possible that the connection timed out and was closed while being pooled.
You can change this to RecyclingMethod::Verified which does perform a test query to ensure the connection is in working condition.
The Manager::from_config gives you the ability to pass in a ManagerConfig.
Sadly diesel doesn't provide access to the underlying database object to check the connection. e.g. deadpool-postgres
also supports multiple RecycleMethods but Fast
does actually check Client::is_closed() and doesn't usually run into this issue.
I found that using Verified sometimes takes a long time. How can I solve this problem? Is it caused by reconnecting to the MySQL pool? Isn't there a specified number of connections waiting to be connected in the connection pool at any time?
That is to be expected if all pooled connections are dead.
Right now deadpool is only active when fetching objects from it. Let's assume you got N objects in the pool and all of them are dead. Deadpool will first try to recycle them all and then fall back to creating new ones.
I do plan on adding some kind of ahead of time object creation/recycling but that feature is still a bit on the drawing board as I want this kind of behavior to be opt in:
Duplicate of #167
deadpool_diesel error after a while diesel error info:Lost connection to MySQL server during query