From b7e844a1543c2d7b23177e06168365089c1055b3 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 18 May 2022 14:04:51 +0100 Subject: [PATCH] hack: set_receipient earlier to avoid a race condition It seems that we have a race-condition pre-existing on master: ```diff diff --git a/tools/mock_node/src/setup.rs b/tools/mock_node/src/setup.rs index 501722c07..0378cf0f9 100644 --- a/tools/mock_node/src/setup.rs +++ b/tools/mock_node/src/setup.rs @@ -342,6 +342,7 @@ pub fn setup_mock_node( #[cfg(feature = "test_features")] let server = None; + std::thread::sleep_ms(300); network_adapter.set_recipient(mock_network_actor.clone().recipient()); (mock_network_actor, client_actor, view_client, server) } ``` and then ``` $ cargo test -p mock_node --lib -- test_mock_node_basic ``` fail for me. THe current actix upgrade seems to exacebrate the issues, alegedly because start_http now takes longer. Work-around this by tying the know earlier. --- nearcore/src/lib.rs | 3 +-- tools/mock_node/src/setup.rs | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/nearcore/src/lib.rs b/nearcore/src/lib.rs index 12225ec29fd..3e5b6a241c8 100644 --- a/nearcore/src/lib.rs +++ b/nearcore/src/lib.rs @@ -323,6 +323,7 @@ pub fn start_with_config_and_synchronization( ) .unwrap() }); + network_adapter.set_recipient(network_actor.recipient()); #[cfg(feature = "json_rpc")] if let Some(rpc_config) = config.rpc_config { @@ -351,8 +352,6 @@ pub fn start_with_config_and_synchronization( )); } - network_adapter.set_recipient(network_actor.recipient()); - rpc_servers.shrink_to_fit(); trace!(target: "diagnostic", key="log", "Starting NEAR node with diagnostic activated"); diff --git a/tools/mock_node/src/setup.rs b/tools/mock_node/src/setup.rs index 7d9a37c18be..abaf33dd6d6 100644 --- a/tools/mock_node/src/setup.rs +++ b/tools/mock_node/src/setup.rs @@ -327,6 +327,7 @@ pub fn setup_mock_node( !archival, ) }); + network_adapter.set_recipient(mock_network_actor.clone().recipient()); // for some reason, with "test_features", start_http requires PeerManagerActor, // we are not going to run start_mock_network with test_features, so let's disable that for now @@ -342,7 +343,6 @@ pub fn setup_mock_node( #[cfg(feature = "test_features")] let server = None; - network_adapter.set_recipient(mock_network_actor.clone().recipient()); (mock_network_actor, client_actor, view_client, server) }