@@ -592,7 +592,7 @@ impl<T: Poolable> Checkout<T> {
592
592
}
593
593
}
594
594
595
- fn checkout ( & mut self ) -> Option < Pooled < T > > {
595
+ fn checkout ( & mut self , cx : & mut task :: Context < ' _ > ) -> Option < Pooled < T > > {
596
596
let entry = {
597
597
let mut inner = self . pool . inner . as_ref ( ) ?. lock ( ) . unwrap ( ) ;
598
598
let expiration = Expiration :: new ( inner. timeout ) ;
@@ -623,14 +623,16 @@ impl<T: Poolable> Checkout<T> {
623
623
}
624
624
625
625
if entry. is_none ( ) && self . waiter . is_none ( ) {
626
- let ( tx, rx) = oneshot:: channel ( ) ;
626
+ let ( tx, mut rx) = oneshot:: channel ( ) ;
627
627
trace ! ( "checkout waiting for idle connection: {:?}" , self . key) ;
628
628
inner
629
629
. waiters
630
630
. entry ( self . key . clone ( ) )
631
631
. or_insert ( VecDeque :: new ( ) )
632
632
. push_back ( tx) ;
633
633
634
+ // register the waker with this oneshot
635
+ assert ! ( Pin :: new( & mut rx) . poll( cx) . is_pending( ) ) ;
634
636
self . waiter = Some ( rx) ;
635
637
}
636
638
@@ -649,14 +651,14 @@ impl<T: Poolable> Future for Checkout<T> {
649
651
return Poll :: Ready ( Ok ( pooled) ) ;
650
652
}
651
653
652
- if let Some ( pooled) = self . checkout ( ) {
654
+ if let Some ( pooled) = self . checkout ( cx ) {
653
655
Poll :: Ready ( Ok ( pooled) )
654
656
} else if !self . pool . is_enabled ( ) {
655
657
Poll :: Ready ( Err ( crate :: Error :: new_canceled ( ) . with ( "pool is disabled" ) ) )
656
658
} else {
657
- // There's a new waiter, but there's no way it should be ready yet.
658
- // We just need to register the waker.
659
- self . poll_waiter ( cx ) . map ( |_| unreachable ! ( ) )
659
+ // There's a new waiter, already registered in self.checkout()
660
+ debug_assert ! ( self . waiter . is_some ( ) ) ;
661
+ Poll :: Pending
660
662
}
661
663
}
662
664
}
0 commit comments