2222
2323use crate :: protocol;
2424use futures:: future:: { BoxFuture , FutureExt } ;
25- use futures:: stream:: { FuturesUnordered , StreamExt } ;
2625use instant:: Instant ;
2726use libp2p_core:: either:: { EitherError , EitherOutput } ;
2827use libp2p_core:: multiaddr:: Multiaddr ;
@@ -144,10 +143,9 @@ pub struct Handler {
144143 <Self as ConnectionHandler >:: Error ,
145144 > ,
146145 > ,
147- /// Inbound connects, accepted by the behaviour, pending completion.
148- inbound_connects : FuturesUnordered <
149- BoxFuture < ' static , Result < Vec < Multiaddr > , protocol:: inbound:: UpgradeError > > ,
150- > ,
146+ /// Inbound connect, accepted by the behaviour, pending completion.
147+ inbound_connect :
148+ Option < BoxFuture < ' static , Result < Vec < Multiaddr > , protocol:: inbound:: UpgradeError > > > ,
151149 keep_alive : KeepAlive ,
152150}
153151
@@ -157,7 +155,7 @@ impl Handler {
157155 endpoint,
158156 pending_error : Default :: default ( ) ,
159157 queued_events : Default :: default ( ) ,
160- inbound_connects : Default :: default ( ) ,
158+ inbound_connect : Default :: default ( ) ,
161159 keep_alive : KeepAlive :: Until ( Instant :: now ( ) + Duration :: from_secs ( 30 ) ) ,
162160 }
163161 }
@@ -247,8 +245,15 @@ impl ConnectionHandler for Handler {
247245 inbound_connect,
248246 obs_addrs,
249247 } => {
250- self . inbound_connects
251- . push ( inbound_connect. accept ( obs_addrs) . boxed ( ) ) ;
248+ if let Some ( _) = self
249+ . inbound_connect
250+ . replace ( inbound_connect. accept ( obs_addrs) . boxed ( ) )
251+ {
252+ log:: warn!(
253+ "New inbound connect stream while still upgrading previous one. \
254+ Replacing previous with new.",
255+ ) ;
256+ }
252257 }
253258 Command :: UpgradeFinishedDontKeepAlive => {
254259 self . keep_alive = KeepAlive :: No ;
@@ -364,7 +369,8 @@ impl ConnectionHandler for Handler {
364369 return Poll :: Ready ( event) ;
365370 }
366371
367- while let Poll :: Ready ( Some ( result) ) = self . inbound_connects . poll_next_unpin ( cx) {
372+ if let Some ( Poll :: Ready ( result) ) = self . inbound_connect . as_mut ( ) . map ( |f| f. poll_unpin ( cx) ) {
373+ self . inbound_connect = None ;
368374 match result {
369375 Ok ( addresses) => {
370376 return Poll :: Ready ( ConnectionHandlerEvent :: Custom (
0 commit comments