Skip to content

Commit

Permalink
Don't wait for p2p-server thread
Browse files Browse the repository at this point in the history
Currently p2p.stop() stops and wait for all peers to exit, that's
basically all we need. However we also run a TCP listener in this thread
which is blocked on `accept` most of the time. We do an attempt to stop
it but it would work only if we get an incoming connection during the
shutdown, which is a week guarantee.

This fix remove joining to p2p-server thread, it stops all peers and
makes an attempt to stop the listener.

Fixes [mimblewimble#2906]
  • Loading branch information
hashmap committed Jun 25, 2019
1 parent 71d16d1 commit 42eef7f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions servers/src/grin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ pub struct Server {
connect_thread: Option<JoinHandle<()>>,
sync_thread: JoinHandle<()>,
dandelion_thread: JoinHandle<()>,
p2p_thread: JoinHandle<()>,
}

impl Server {
Expand Down Expand Up @@ -256,7 +255,7 @@ impl Server {
)?;

let p2p_inner = p2p_server.clone();
let p2p_thread = thread::Builder::new()
let _ = thread::Builder::new()
.name("p2p-server".to_string())
.spawn(move || {
if let Err(e) = p2p_inner.listen() {
Expand Down Expand Up @@ -315,7 +314,6 @@ impl Server {
lock_file,
connect_thread,
sync_thread,
p2p_thread,
dandelion_thread,
})
}
Expand Down Expand Up @@ -530,11 +528,9 @@ impl Server {
Ok(_) => info!("dandelion_monitor thread stopped"),
}
}
// this call is blocking and makes sure all peers stop, however
// we can't be sure that we stoped a listener blocked on accept, so we don't join the p2p thread
self.p2p.stop();
match self.p2p_thread.join() {
Err(e) => error!("failed to join to p2p thread: {:?}", e),
Ok(_) => info!("p2p thread stopped"),
}
let _ = self.lock_file.unlock();
}

Expand Down

0 comments on commit 42eef7f

Please sign in to comment.