@@ -8,8 +8,8 @@ use either::Either;
88use libp2p_core:: { Endpoint , Multiaddr , transport:: PortUse } ;
99use libp2p_identity:: PeerId ;
1010use libp2p_swarm:: {
11- ConnectionDenied , ConnectionHandler , ConnectionId , DialFailure , FromSwarm , NetworkBehaviour ,
12- ToSwarm ,
11+ CloseConnection , ConnectionDenied , ConnectionHandler , ConnectionId , DialFailure , FromSwarm ,
12+ NetworkBehaviour , ToSwarm ,
1313 dial_opts:: { DialOpts , PeerCondition } ,
1414 dummy,
1515} ;
@@ -102,13 +102,23 @@ where
102102 fn on_connection_handler_event (
103103 & mut self ,
104104 peer_id : PeerId ,
105- _connection_id : ConnectionId ,
105+ connection_id : ConnectionId ,
106106 event : <Handler < R > as ConnectionHandler >:: ToBehaviour ,
107107 ) {
108108 match event {
109- Either :: Left ( Either :: Left ( Ok ( _) ) ) => { }
110- Either :: Left ( Either :: Left ( Err ( e) ) ) => {
111- tracing:: debug!( "dial back error: {e:?}" ) ;
109+ Either :: Left ( Either :: Left ( result) ) => {
110+ if let Err ( e) = result {
111+ tracing:: debug!( "dial back error: {e:?}" ) ;
112+ }
113+ // This connection was dialed solely to perform the dial-back, which
114+ // has now run to completion; the outcome reaches the client over the
115+ // connection it dialed us on. Close the dial-back connection so it
116+ // does not linger alongside the client's primary connection and hold
117+ // on to transport resources.
118+ self . pending_events . push_back ( ToSwarm :: CloseConnection {
119+ peer_id,
120+ connection : CloseConnection :: One ( connection_id) ,
121+ } ) ;
112122 }
113123 Either :: Left ( Either :: Right ( v) ) => libp2p_core:: util:: unreachable ( v) ,
114124 Either :: Right ( Either :: Left ( cmd) ) => {
0 commit comments