Skip to content

Commit

Permalink
receive_and_buffer exit condition fix
Browse files Browse the repository at this point in the history
  • Loading branch information
apfitzge committed Nov 27, 2024
1 parent d86e41b commit c868ff5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/src/banking_stage/transaction_scheduler/receive_and_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ pub(crate) trait ReceiveAndBuffer {
type Transaction: TransactionWithMeta + Send + Sync;
type Container: StateContainer<Self::Transaction> + Send + Sync;

/// Returns whether the packet receiver is still connected.
/// Returns false only if no packets were received
/// AND the receiver is disconnected.
fn receive_and_buffer_packets(
&mut self,
container: &mut Self::Container,
Expand Down Expand Up @@ -312,6 +313,7 @@ impl ReceiveAndBuffer for TransactionViewReceiveAndBuffer {
// Receive packet batches.
const TIMEOUT: Duration = Duration::from_millis(10);
let start = Instant::now();
let mut received_message = false;

// If not leader, do a blocking-receive initially. This lets the thread
// sleep when there is not work to do.
Expand All @@ -327,6 +329,7 @@ impl ReceiveAndBuffer for TransactionViewReceiveAndBuffer {
) {
match self.receiver.recv_timeout(TIMEOUT) {
Ok(packet_batch_message) => {
received_message = true;
self.handle_packet_batch_message(
container,
timing_metrics,
Expand All @@ -336,13 +339,16 @@ impl ReceiveAndBuffer for TransactionViewReceiveAndBuffer {
);
}
Err(RecvTimeoutError::Timeout) => return true,
Err(RecvTimeoutError::Disconnected) => return false,
Err(RecvTimeoutError::Disconnected) => {
return received_message;
}
}
}

while start.elapsed() < TIMEOUT {
match self.receiver.try_recv() {
Ok(packet_batch_message) => {
received_message = true;
self.handle_packet_batch_message(
container,
timing_metrics,
Expand All @@ -352,7 +358,9 @@ impl ReceiveAndBuffer for TransactionViewReceiveAndBuffer {
);
}
Err(TryRecvError::Empty) => return true,
Err(TryRecvError::Disconnected) => return false,
Err(TryRecvError::Disconnected) => {
return received_message;
}
}
}

Expand Down

0 comments on commit c868ff5

Please sign in to comment.