Skip to content

Commit bd39374

Browse files
authored
Merge pull request #5311 from stacks-network/fix/port-bind-error
CI fix: Fix occasional port bind error happening in mock mining
2 parents 77121b8 + daeed4c commit bd39374

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

stackslib/src/net/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl NetworkState {
8989
}
9090

9191
fn bind_address(addr: &SocketAddr) -> Result<mio_net::TcpListener, net_error> {
92-
if !cfg!(test) {
92+
if !cfg!(test) && !cfg!(feature = "testing") {
9393
mio_net::TcpListener::bind(addr).map_err(|e| {
9494
error!("Failed to bind to {:?}: {:?}", addr, e);
9595
net_error::BindError

testnet/stacks-node/src/tests/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use clarity::vm::events::STXEventType;
2323
use clarity::vm::types::PrincipalData;
2424
use clarity::vm::{ClarityName, ClarityVersion, ContractName, Value};
2525
use lazy_static::lazy_static;
26+
use neon_integrations::test_observer::EVENT_OBSERVER_PORT;
2627
use rand::Rng;
2728
use stacks::chainstate::burn::ConsensusHash;
2829
use stacks::chainstate::stacks::db::StacksChainState;
@@ -101,7 +102,11 @@ lazy_static! {
101102
}
102103

103104
lazy_static! {
104-
static ref USED_PORTS: Mutex<HashSet<u16>> = Mutex::new(HashSet::new());
105+
static ref USED_PORTS: Mutex<HashSet<u16>> = Mutex::new({
106+
let mut set = HashSet::new();
107+
set.insert(EVENT_OBSERVER_PORT);
108+
set
109+
});
105110
}
106111

107112
/// Generate a random port number between 1024 and 65534 (inclusive) and insert it into the USED_PORTS set.

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8598,16 +8598,16 @@ fn mock_mining() {
85988598
let send_amt = 100;
85998599
let send_fee = 180;
86008600

8601-
let node_1_rpc = 51024;
8602-
let node_1_p2p = 51023;
8603-
let node_2_rpc = 51026;
8604-
let node_2_p2p = 51025;
8601+
let node_1_rpc = gen_random_port();
8602+
let node_1_p2p = gen_random_port();
8603+
let node_2_rpc = gen_random_port();
8604+
let node_2_p2p = gen_random_port();
86058605

86068606
let localhost = "127.0.0.1";
8607-
naka_conf.node.rpc_bind = format!("{}:{}", localhost, node_1_rpc);
8608-
naka_conf.node.p2p_bind = format!("{}:{}", localhost, node_1_p2p);
8609-
naka_conf.node.data_url = format!("http://{}:{}", localhost, node_1_rpc);
8610-
naka_conf.node.p2p_address = format!("{}:{}", localhost, node_1_p2p);
8607+
naka_conf.node.rpc_bind = format!("{localhost}:{node_1_rpc}");
8608+
naka_conf.node.p2p_bind = format!("{localhost}:{node_1_p2p}");
8609+
naka_conf.node.data_url = format!("http://{localhost}:{node_1_rpc}");
8610+
naka_conf.node.p2p_address = format!("{localhost}:{node_1_p2p}");
86118611
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
86128612

86138613
naka_conf.add_initial_balance(
@@ -8687,10 +8687,10 @@ fn mock_mining() {
86878687
follower_conf.node.seed = vec![0x01; 32];
86888688
follower_conf.node.local_peer_seed = vec![0x02; 32];
86898689

8690-
follower_conf.node.rpc_bind = format!("{}:{}", localhost, node_2_rpc);
8691-
follower_conf.node.p2p_bind = format!("{}:{}", localhost, node_2_p2p);
8692-
follower_conf.node.data_url = format!("http://{}:{}", localhost, node_2_rpc);
8693-
follower_conf.node.p2p_address = format!("{}:{}", localhost, node_2_p2p);
8690+
follower_conf.node.rpc_bind = format!("{localhost}:{node_2_rpc}");
8691+
follower_conf.node.p2p_bind = format!("{localhost}:{node_2_p2p}");
8692+
follower_conf.node.data_url = format!("http://{localhost}:{node_2_rpc}");
8693+
follower_conf.node.p2p_address = format!("{localhost}:{node_2_p2p}");
86948694

86958695
let node_info = get_chain_info(&naka_conf);
86968696
follower_conf.node.add_bootstrap_node(

0 commit comments

Comments
 (0)