Skip to content

Commit 8ed1aaf

Browse files
committed
remove redundant timeouts
1 parent 703677b commit 8ed1aaf

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

gossip/src/cluster_info.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use {
4242
},
4343
weighted_shuffle::WeightedShuffle,
4444
},
45-
crossbeam_channel::{Receiver, RecvTimeoutError, Sender, TrySendError},
45+
crossbeam_channel::{Receiver, Sender, TrySendError},
4646
itertools::{Either, Itertools},
4747
rand::{seq::SliceRandom, CryptoRng, Rng},
4848
rayon::{prelude::*, ThreadPool, ThreadPoolBuilder},
@@ -2112,7 +2112,6 @@ impl ClusterInfo {
21122112
sender: &Sender<Vec<(/*from:*/ SocketAddr, Protocol)>>,
21132113
packet_buf: &mut VecDeque<PacketBatch>,
21142114
) -> Result<(), GossipError> {
2115-
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
21162115
fn count_dropped_packets(packets: &PacketBatch, dropped_packets_counts: &mut [u64; 7]) {
21172116
for packet in packets {
21182117
let k = packet
@@ -2127,7 +2126,7 @@ impl ClusterInfo {
21272126
let mut dropped_packets_counts = [0u64; 7];
21282127
let mut num_packets = 0;
21292128
for packet_batch in receiver
2130-
.recv_timeout(RECV_TIMEOUT)
2129+
.recv()
21312130
.map(std::iter::once)?
21322131
.chain(receiver.try_iter())
21332132
{
@@ -2218,10 +2217,9 @@ impl ClusterInfo {
22182217
packet_buf: &mut VecDeque<Vec<(/*from:*/ SocketAddr, Protocol)>>,
22192218
) -> Result<(), GossipError> {
22202219
let _st = ScopedTimer::from(&self.stats.gossip_listen_loop_time);
2221-
const RECV_TIMEOUT: Duration = Duration::from_secs(1);
22222220
let mut num_packets = 0;
22232221
for pkts in receiver
2224-
.recv_timeout(RECV_TIMEOUT)
2222+
.recv()
22252223
.map(std::iter::once)?
22262224
.chain(receiver.try_iter())
22272225
{
@@ -2287,8 +2285,9 @@ impl ClusterInfo {
22872285
&sender,
22882286
&mut packet_buf,
22892287
) {
2290-
Err(GossipError::RecvTimeoutError(RecvTimeoutError::Disconnected)) => break,
2291-
Err(GossipError::RecvTimeoutError(RecvTimeoutError::Timeout)) => (),
2288+
// A recv operation can only fail if the sending end of a
2289+
// channel is disconnected.
2290+
Err(GossipError::RecvError(_)) => break,
22922291
// A send operation can only fail if the receiving end of a
22932292
// channel is disconnected.
22942293
Err(GossipError::SendError) => break,
@@ -2331,15 +2330,7 @@ impl ClusterInfo {
23312330
&mut packet_buf,
23322331
) {
23332332
match err {
2334-
GossipError::RecvTimeoutError(RecvTimeoutError::Disconnected) => break,
2335-
GossipError::RecvTimeoutError(RecvTimeoutError::Timeout) => {
2336-
let table_size = self.gossip.crds.read().unwrap().len();
2337-
debug!(
2338-
"{}: run_listen timeout, table size: {}",
2339-
self.id(),
2340-
table_size,
2341-
);
2342-
}
2333+
GossipError::RecvError(_) => break,
23432334
GossipError::DuplicateNodeInstance => {
23442335
error!(
23452336
"duplicate running instances of the same validator node: {}",

gossip/src/gossip_error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use {
22
crate::{contact_info, duplicate_shred},
3-
crossbeam_channel::{RecvTimeoutError, SendError},
3+
crossbeam_channel::{RecvError, SendError},
44
std::io,
55
thiserror::Error,
66
};
@@ -16,7 +16,7 @@ pub enum GossipError {
1616
#[error(transparent)]
1717
Io(#[from] io::Error),
1818
#[error(transparent)]
19-
RecvTimeoutError(#[from] RecvTimeoutError),
19+
RecvError(#[from] RecvError),
2020
#[error("send error")]
2121
SendError,
2222
#[error("serialization error")]

0 commit comments

Comments
 (0)