@@ -77,6 +77,7 @@ pub struct PoolOptions<DB: Database> {
7777 pub ( crate ) max_connections : u32 ,
7878 pub ( crate ) acquire_time_level : LevelFilter ,
7979 pub ( crate ) acquire_slow_level : LevelFilter ,
80+ pub ( crate ) return_con_refused : bool ,
8081 pub ( crate ) acquire_slow_threshold : Duration ,
8182 pub ( crate ) acquire_timeout : Duration ,
8283 pub ( crate ) min_connections : u32 ,
@@ -101,6 +102,7 @@ impl<DB: Database> Clone for PoolOptions<DB> {
101102 acquire_time_level : self . acquire_time_level ,
102103 acquire_slow_threshold : self . acquire_slow_threshold ,
103104 acquire_slow_level : self . acquire_slow_level ,
105+ return_con_refused : self . return_con_refused ,
104106 acquire_timeout : self . acquire_timeout ,
105107 min_connections : self . min_connections ,
106108 max_lifetime : self . max_lifetime ,
@@ -154,6 +156,7 @@ impl<DB: Database> PoolOptions<DB> {
154156 acquire_time_level : LevelFilter :: Off ,
155157 // Default to warning, because an acquire timeout will be an error
156158 acquire_slow_level : LevelFilter :: Warn ,
159+ return_con_refused : false ,
157160 // Fast enough to catch problems (e.g. a full pool); slow enough
158161 // to not flag typical time to add a new connection to a pool.
159162 acquire_slow_threshold : Duration :: from_secs ( 2 ) ,
@@ -229,6 +232,13 @@ impl<DB: Database> PoolOptions<DB> {
229232 self
230233 }
231234
235+ /// immediately return connection refused errors instead of hanging
236+ /// until returning PoolTimedOut
237+ pub fn return_con_refused ( mut self , value : bool ) -> Self {
238+ self . return_con_refused = value;
239+ self
240+ }
241+
232242 /// Set a threshold for reporting excessive time taken to acquire a connection from
233243 /// the connection pool via [`Pool::acquire()`]. When the threshold is exceeded, a warning is logged.
234244 ///
0 commit comments