@@ -161,7 +161,6 @@ use std::convert::TryInto;
161161use std:: default:: Default ;
162162use std:: fs;
163163use std:: net:: ToSocketAddrs ;
164- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
165164use std:: sync:: { Arc , Mutex , RwLock } ;
166165use std:: time:: { Duration , Instant , SystemTime } ;
167166
@@ -1208,22 +1207,16 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
12081207
12091208 let con_node_id = peer_info. node_id ;
12101209 let con_addr = peer_info. address . clone ( ) ;
1211- let con_success = Arc :: new ( AtomicBool :: new ( false ) ) ;
1212- let con_success_cloned = Arc :: clone ( & con_success) ;
12131210 let con_logger = Arc :: clone ( & self . logger ) ;
12141211 let con_pm = Arc :: clone ( & self . peer_manager ) ;
12151212
1213+ // We need to use our main runtime here as a local runtime might not be around to poll
1214+ // connection futures going forward.
12161215 tokio:: task:: block_in_place ( move || {
12171216 runtime. block_on ( async move {
1218- let res =
1219- connect_peer_if_necessary ( con_node_id, con_addr, con_pm, con_logger) . await ;
1220- con_success_cloned. store ( res. is_ok ( ) , Ordering :: Release ) ;
1217+ connect_peer_if_necessary ( con_node_id, con_addr, con_pm, con_logger) . await
12211218 } )
1222- } ) ;
1223-
1224- if !con_success. load ( Ordering :: Acquire ) {
1225- return Err ( Error :: ConnectionFailed ) ;
1226- }
1219+ } ) ?;
12271220
12281221 log_info ! ( self . logger, "Connected to peer {}@{}. " , peer_info. node_id, peer_info. address) ;
12291222
@@ -1286,22 +1279,16 @@ impl<K: KVStore + Sync + Send + 'static> Node<K> {
12861279
12871280 let con_node_id = peer_info. node_id ;
12881281 let con_addr = peer_info. address . clone ( ) ;
1289- let con_success = Arc :: new ( AtomicBool :: new ( false ) ) ;
1290- let con_success_cloned = Arc :: clone ( & con_success) ;
12911282 let con_logger = Arc :: clone ( & self . logger ) ;
12921283 let con_pm = Arc :: clone ( & self . peer_manager ) ;
12931284
1285+ // We need to use our main runtime here as a local runtime might not be around to poll
1286+ // connection futures going forward.
12941287 tokio:: task:: block_in_place ( move || {
12951288 runtime. block_on ( async move {
1296- let res =
1297- connect_peer_if_necessary ( con_node_id, con_addr, con_pm, con_logger) . await ;
1298- con_success_cloned. store ( res. is_ok ( ) , Ordering :: Release ) ;
1289+ connect_peer_if_necessary ( con_node_id, con_addr, con_pm, con_logger) . await
12991290 } )
1300- } ) ;
1301-
1302- if !con_success. load ( Ordering :: Acquire ) {
1303- return Err ( Error :: ConnectionFailed ) ;
1304- }
1291+ } ) ?;
13051292
13061293 let user_config = UserConfig {
13071294 channel_handshake_limits : ChannelHandshakeLimits {
0 commit comments