Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions crates/rollup-boost/src/flashblocks/inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,36 @@ impl FlashblocksReceiverService {

pub async fn run(self) {
let mut backoff = self.websocket_config.backoff();
info!("FlashblocksReceiverService starting reconnection loop");
loop {
if let Err(e) = self.connect_and_handle(&mut backoff).await {
let interval = backoff
.next_backoff()
.expect("max_elapsed_time not set, never None");
error!(
"Flashblocks receiver connection error, retrying in {}ms: {}",
interval.as_millis(),
e
);
self.metrics.reconnect_attempts.increment(1);
self.metrics.connection_status.set(0);
tokio::time::sleep(interval).await;
} else {
break;
match self.connect_and_handle(&mut backoff).await {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 changes were made here:

  1. remove the break part, we expect the receiver to always run unless the service gets shutdown
  2. Added some logging to help triage problems if it came up again.

Err(e) => {
// Get next backoff interval, or use max if None (defensive)
let interval = backoff
.next_backoff()
.unwrap_or_else(|| {
error!("Backoff returned None despite max_elapsed_time=None, using max_interval as fallback");
self.websocket_config.max_interval()
});
error!(
"Flashblocks receiver connection error, retrying in {}ms: {}",
interval.as_millis(),
e
);
self.metrics.reconnect_attempts.increment(1);
self.metrics.connection_status.set(0);
tokio::time::sleep(interval).await;
}
Ok(()) => {
// This should never happen - connect_and_handle should loop forever
// or return an error. If we get here, reconnect immediately.
error!(
"Flashblocks receiver connection ended unexpectedly with Ok(()), this should never happen. Reconnecting immediately."
);
self.metrics.reconnect_attempts.increment(1);
self.metrics.connection_status.set(0);
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider resetting the backoff in the Ok(()) branch to ensure clean state for the next reconnection attempt. Even though this case should never happen, if it does occur after several failed attempts with exponential backoff, the next error would use an inflated backoff interval.

Ok(()) => {
    // This should never happen - connect_and_handle should loop forever
    // or return an error. If we get here, reconnect immediately.
    error!(
        "Flashblocks receiver connection ended unexpectedly with Ok(()), this should never happen. Reconnecting immediately."
    );
    self.metrics.reconnect_attempts.increment(1);
    self.metrics.connection_status.set(0);
    backoff.reset(); // Reset backoff for clean state
    // Reconnect immediately without delay since this is unexpected
}
Suggested change
self.metrics.connection_status.set(0);
self.metrics.connection_status.set(0);
backoff.reset(); // Reset backoff for clean state

Copilot uses AI. Check for mistakes.
// Reconnect immediately without delay since this is unexpected
}
}
}
}
Expand Down
Loading