From 68b8800c4cfe27918df8c9756a3614e9c8743deb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 11 Feb 2021 18:54:51 +0300 Subject: [PATCH] Demonstrate leaked threads 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. --- chain/network/src/peer.rs | 8 ++++++++ chain/network/src/peer_manager.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/chain/network/src/peer.rs b/chain/network/src/peer.rs index 026ef16aa64..38abff9f029 100644 --- a/chain/network/src/peer.rs +++ b/chain/network/src/peer.rs @@ -184,6 +184,14 @@ pub struct Peer { peer_counter: Arc, } +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, diff --git a/chain/network/src/peer_manager.rs b/chain/network/src/peer_manager.rs index efb35cd72be..092f80fc53e 100644 --- a/chain/network/src/peer_manager.rs +++ b/chain/network/src/peer_manager.rs @@ -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,