Skip to content

Commit

Permalink
Demonstrate leaked threads
Browse files Browse the repository at this point in the history
If I run

  cargo t  -p neard --test run_nodes -- run_nodes_1_2_1 --nocapture --test-threads 1

I see

  will drop PeerManagerActor

but not

  did drop PeerManagerActor

This means that the corresponding thread is being abruptly terminated.
  • Loading branch information
matklad committed Feb 11, 2021
1 parent 1cb9302 commit 68b8800
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions chain/network/src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ pub struct Peer {
peer_counter: Arc<AtomicUsize>,
}

impl Drop for Peer {
fn drop(&mut self) {
eprintln!("will drop Peer");
std::thread::sleep(std::time::Duration::from_millis(250));
eprintln!("did drop Peer");
}
}

impl Peer {
pub fn new(
node_info: PeerInfo,
Expand Down
8 changes: 8 additions & 0 deletions chain/network/src/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ pub struct PeerManagerActor {
scheduled_routing_table_update: bool,
}

impl Drop for PeerManagerActor {
fn drop(&mut self) {
eprintln!("will drop PeerManagerActor");
std::thread::sleep(std::time::Duration::from_millis(250));
eprintln!("did drop PeerManagerActor");
}
}

impl PeerManagerActor {
pub fn new(
store: Arc<Store>,
Expand Down

0 comments on commit 68b8800

Please sign in to comment.