@@ -19,7 +19,7 @@ use super::{
1919 DEFAULT_MAX_POOL_SIZE ,
2020} ;
2121use crate :: {
22- error:: Result ,
22+ error:: { Error , ErrorKind , Result } ,
2323 event:: cmap:: {
2424 CmapEventHandler ,
2525 ConnectionClosedEvent ,
@@ -172,7 +172,7 @@ impl ConnectionPoolWorker {
172172 {
173173 PoolState :: Ready
174174 } else {
175- PoolState :: Paused
175+ PoolState :: New
176176 } ;
177177 #[ cfg( test) ]
178178 let maintenance_frequency = options
@@ -181,7 +181,7 @@ impl ConnectionPoolWorker {
181181 . unwrap_or ( MAINTENACE_FREQUENCY ) ;
182182
183183 #[ cfg( not( test) ) ]
184- let ( state, maintenance_frequency) = ( PoolState :: Paused , MAINTENACE_FREQUENCY ) ;
184+ let ( state, maintenance_frequency) = ( PoolState :: New , MAINTENACE_FREQUENCY ) ;
185185
186186 let worker = ConnectionPoolWorker {
187187 address,
@@ -244,16 +244,27 @@ impl ConnectionPoolWorker {
244244 PoolState :: Ready => {
245245 self . wait_queue . push_back ( request) ;
246246 }
247- PoolState :: Paused => {
247+ PoolState :: Paused ( ref e ) => {
248248 // if receiver doesn't listen to error that's ok.
249- let _ = request. fulfill ( ConnectionRequestResult :: PoolCleared ) ;
249+ let _ = request. fulfill ( ConnectionRequestResult :: PoolCleared ( e. clone ( ) ) ) ;
250+ }
251+ PoolState :: New => {
252+ let _ = request. fulfill ( ConnectionRequestResult :: PoolCleared (
253+ ErrorKind :: Internal {
254+ message : "check out attempted from new pool" . to_string ( ) ,
255+ }
256+ . into ( ) ,
257+ ) ) ;
250258 }
251259 } ,
252260 PoolTask :: HandleManagementRequest ( PoolManagementRequest :: CheckIn ( connection) ) => {
253261 self . check_in ( connection)
254262 }
255- PoolTask :: HandleManagementRequest ( PoolManagementRequest :: Clear ( _message) ) => {
256- self . clear ( ) ;
263+ PoolTask :: HandleManagementRequest ( PoolManagementRequest :: Clear {
264+ completion_handler : _,
265+ cause,
266+ } ) => {
267+ self . clear ( cause) ;
257268 }
258269 PoolTask :: HandleManagementRequest ( PoolManagementRequest :: MarkAsReady {
259270 completion_handler : _handler,
@@ -428,12 +439,12 @@ impl ConnectionPoolWorker {
428439 }
429440 }
430441
431- fn clear ( & mut self ) {
442+ fn clear ( & mut self , cause : Error ) {
432443 self . generation += 1 ;
433- let previous_state = std:: mem:: replace ( & mut self . state , PoolState :: Paused ) ;
444+ let previous_state = std:: mem:: replace ( & mut self . state , PoolState :: Paused ( cause . clone ( ) ) ) ;
434445 self . generation_publisher . publish ( self . generation ) ;
435446
436- if ! matches ! ( previous_state, PoolState :: Paused ) {
447+ if matches ! ( previous_state, PoolState :: Ready ) {
437448 self . emit_event ( |handler| {
438449 let event = PoolClearedEvent {
439450 address : self . address . clone ( ) ,
@@ -446,7 +457,7 @@ impl ConnectionPoolWorker {
446457 // an error means the other end hung up already, which is okay because we were
447458 // returning an error anyways
448459 let _: std:: result:: Result < _ , _ > =
449- request. fulfill ( ConnectionRequestResult :: PoolCleared ) ;
460+ request. fulfill ( ConnectionRequestResult :: PoolCleared ( cause . clone ( ) ) ) ;
450461 }
451462 }
452463 }
@@ -583,8 +594,11 @@ async fn establish_connection(
583594/// once it goes out of scope and cannot be manually closed before then.
584595#[ derive( Debug ) ]
585596enum PoolState {
597+ /// Same as Paused, but only for a new pool, not one that has been cleared due to an error.
598+ New ,
599+
586600 /// Connections may not be checked out nor created in the background to satisfy minPoolSize.
587- Paused ,
601+ Paused ( Error ) ,
588602
589603 /// Pool is operational.
590604 Ready ,
0 commit comments