mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 22:43:42 +08:00
fix: Skip PeerNetwork::bind() if re-using object
This commit is contained in:
@@ -646,6 +646,24 @@ impl PeerNetwork {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Call `bind()` only if not already bound
|
||||
/// Returns:
|
||||
/// - `Ok(true)` if `bind()` call was successful
|
||||
/// - `Ok(false)` if `bind()` call was skipped
|
||||
/// - `Err()` if `bind()`` failed
|
||||
#[cfg_attr(test, mutants::skip)]
|
||||
pub fn try_bind(
|
||||
&mut self,
|
||||
my_addr: &SocketAddr,
|
||||
http_addr: &SocketAddr,
|
||||
) -> Result<bool, net_error> {
|
||||
if self.network.is_some() {
|
||||
// Already bound
|
||||
return Ok(false);
|
||||
}
|
||||
self.bind(my_addr, http_addr).map(|()| true)
|
||||
}
|
||||
|
||||
/// Get bound neighbor key. This is how this PeerNetwork appears to other nodes.
|
||||
pub fn bound_neighbor_key(&self) -> &NeighborKey {
|
||||
&self.bind_nk
|
||||
|
||||
@@ -182,8 +182,13 @@ impl PeerThread {
|
||||
.parse()
|
||||
.unwrap_or_else(|_| panic!("Failed to parse socket: {}", &config.node.rpc_bind));
|
||||
|
||||
net.bind(&p2p_sock, &rpc_sock)
|
||||
.expect("BUG: PeerNetwork could not bind or is already bound");
|
||||
let did_bind = net
|
||||
.try_bind(&p2p_sock, &rpc_sock)
|
||||
.expect("BUG: PeerNetwork could not bind");
|
||||
|
||||
if !did_bind {
|
||||
info!("`PeerNetwork::bind()` skipped, already bound");
|
||||
}
|
||||
|
||||
let poll_timeout = cmp::min(5000, config.miner.first_attempt_time_ms / 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user