Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
Introduce dummy lock to sequentialize P2P.connect() (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
tuommaki authored Mar 19, 2024
1 parent 746ae49 commit 92ade6d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/node/src/networking/p2p/pea2pea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct P2P {
peer_list: Arc<tokio::sync::RwLock<BTreeSet<SocketAddr>>>,
// Contains corrected peers that are used for asset file download.
pub peer_http_port_list: Arc<tokio::sync::RwLock<HashMap<SocketAddr, Option<u16>>>>,
connect_lock: Arc<tokio::sync::Mutex<()>>,

http_port: Option<u16>,
nat_listen_addr: Option<SocketAddr>,
Expand Down Expand Up @@ -90,6 +91,7 @@ impl P2P {
peer_list: Default::default(),
peer_addr_mapping: Default::default(),
peer_http_port_list,
connect_lock: Arc::new(tokio::sync::Mutex::new(())),
http_port,
nat_listen_addr,
tx_sender,
Expand Down Expand Up @@ -194,6 +196,9 @@ impl P2P {
#[async_trait::async_trait]
impl Handshake for P2P {
async fn perform_handshake(&self, mut conn: Connection) -> io::Result<Connection> {
// Sequentialize P2P connections to avoid deadlock.
let _lock = self.connect_lock.lock().await;

tracing::debug!("starting handshake");

// Create the noise objects.
Expand Down

0 comments on commit 92ade6d

Please sign in to comment.