From a6bb6344acb65286de67121f1eb249a02f78f82f Mon Sep 17 00:00:00 2001 From: hashmap Date: Fri, 7 Dec 2018 17:09:26 +0100 Subject: [PATCH] Fix seed thread crash (#2096) We get overflow in some tests, peraps in real life too Fixes #2095 --- p2p/src/peers.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/p2p/src/peers.rs b/p2p/src/peers.rs index 609fa1fd..ea115031 100644 --- a/p2p/src/peers.rs +++ b/p2p/src/peers.rs @@ -409,7 +409,9 @@ impl Peers { } // ensure we do not still have too many connected peers - let excess_count = (self.peer_count() as usize - rm.len()).saturating_sub(max_count); + let excess_count = (self.peer_count() as usize) + .saturating_sub(rm.len()) + .saturating_sub(max_count); if excess_count > 0 { // map peers to addrs in a block to bound how long we keep the read lock for let mut addrs = self