Skip to content
Open
Changes from 3 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
20 changes: 19 additions & 1 deletion crates/networking/rpc/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ use tokio::sync::{
mpsc::{UnboundedSender, unbounded_channel},
oneshot,
};
use tokio::time::timeout;
use tower_http::cors::CorsLayer;
use tracing::{error, info};
use tracing_subscriber::{EnvFilter, Registry, reload};
Expand Down Expand Up @@ -296,7 +297,24 @@ pub async fn start_api(
.into_future();
info!("Starting HTTP server at {http_addr}");

let authrpc_handler = |ctx, auth, body| async { handle_authrpc_request(ctx, auth, body).await };
let (timer_sender, mut timer_receiver) = tokio::sync::watch::channel(());

tokio::spawn(async move {
loop {
let result = timeout(Duration::from_secs(30), timer_receiver.changed()).await;
if result.is_err() {
error!("No messages from the consensus layer. Is the consensus client running?
Check the auth JWT coincides with the one used by the CL and the auth RPC address and port used by it and Ethrex match."
);
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

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

The spawned task will panic if the sender is dropped. When timer_receiver.changed() returns an error (which occurs when all senders are dropped), the code logs an error but continues looping. This will cause continuous error logging. The loop should break when changed() returns Err, which indicates the channel is closed.

Suggested change
if result.is_err() {
error!("No messages from the consensus layer. Is the consensus client running?
Check the auth JWT coincides with the one used by the CL and the auth RPC address and port used by it and Ethrex match."
);
match result {
Ok(Ok(_)) => {
// Successfully received a change, continue looping.
}
Ok(Err(_)) | Err(_) => {
error!("No messages from the consensus layer. Is the consensus client running?
Check the auth JWT coincides with the one used by the CL and the auth RPC address and port used by it and Ethrex match."
);
break;
}

Copilot uses AI. Check for mistakes.
}
}
});

let authrpc_handler = async move |ctx, auth, body| {
let _ = timer_sender.send(());
handle_authrpc_request(ctx, auth, body).await
};

let authrpc_router = Router::new()
.route("/", post(authrpc_handler))
.with_state(service_context.clone())
Expand Down