1
0
Fork 0
mirror of https://github.com/romanz/electrs.git synced 2025-02-24 15:02:21 +01:00

Add more logging to thread handling

This commit is contained in:
Roman Zeyde 2020-04-15 22:11:40 +03:00
parent bc45dbfe41
commit 9c2cbfaa3d
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB

View file

@ -563,25 +563,23 @@ impl RPC {
let stats = Arc::clone(&stats);
let garbage_sender = garbage_sender.clone();
// HACK: detach peer-handling threads
let spawned = spawn_thread("peer", move || {
info!("[{}] connected peer", addr);
let conn = Connection::new(query, stream, addr, stats, relayfee);
senders.lock().unwrap().push(conn.chan.sender());
conn.run();
info!("[{}] disconnected peer", addr);
let _ = garbage_sender.send(std::thread::current().id());
let _ = garbage_sender.send(std::thread::current().id());
});
trace!("[{}] spawned {:?}", addr, spawned.thread().id());
threads.insert(spawned.thread().id(), spawned);
while let Ok(id) = garbage_receiver.try_recv() {
let result = threads
.remove(&id)
.map(std::thread::JoinHandle::join)
.transpose();
if let Err(error) = result {
error!("Failed to join thread: {:?}", error);
if let Some(thread) = threads.remove(&id) {
trace!("[{}] joining {:?}", addr, id);
if let Err(error) = thread.join() {
error!("failed to join {:?}: {:?}", id, error);
}
}
}
}
@ -589,9 +587,10 @@ impl RPC {
for sender in senders.lock().unwrap().iter() {
let _ = sender.send(Message::Done);
}
for (_, thread) in threads {
for (id, thread) in threads {
trace!("joining {:?}", id);
if let Err(error) = thread.join() {
error!("Failed to join thread: {:?}", error);
error!("failed to join {:?}: {:?}", id, error);
}
}