Skip to content

Commit

Permalink
gets candidate set and address book locks outside spawned task
Browse files Browse the repository at this point in the history
  • Loading branch information
arya2 committed Nov 21, 2023
1 parent 3be22b2 commit 036c29d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions zebra-network/src/peer_set/initialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,18 +868,18 @@ where
"opening an outbound peer connection"
);

// Try to get the next available peer for a handshake.
//
// candidates.next() has a short timeout, and briefly holds the address
// book lock, so it shouldn't hang.
//
// Hold the lock for as short a time as possible.
let candidate = { candidates.lock().await.next().await };

// Spawn each handshake or crawl into an independent task, so handshakes can make
// progress while crawls are running.
let handshake_or_crawl_handle = tokio::spawn(
async move {
// Try to get the next available peer for a handshake.
//
// candidates.next() has a short timeout, and briefly holds the address
// book lock, so it shouldn't hang.
//
// Hold the lock for as short a time as possible.
let candidate = { candidates.lock().await.next().await };

if let Some(candidate) = candidate {
// we don't need to spawn here, because there's nothing running concurrently
dial(
Expand Down

0 comments on commit 036c29d

Please sign in to comment.