Skip to content

Commit

Permalink
feat: force orderly cancellation even if rpc server or p2p fail to start
Browse files Browse the repository at this point in the history
  • Loading branch information
CHr15F0x committed Dec 23, 2024
1 parent 4f55593 commit b5665cf
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions crates/pathfinder/src/bin/pathfinder/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,16 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syst
p2p_storage,
config.p2p.clone(),
)
.await?;
.await
.unwrap_or_else(|error| {
(
tokio::task::spawn(std::future::ready(
Err(error.context("P2P failed to start")),
)),
Default::default(),
None,
)
});

let sync_handle = if config.is_sync_enabled {
start_sync(
Expand All @@ -303,13 +312,19 @@ Hint: This is usually caused by exceeding the file descriptor limit of your syst
};

let rpc_handle = if config.is_rpc_enabled {
let (rpc_handle, local_addr) = rpc_server
match rpc_server
.with_max_connections(config.max_rpc_connections.get())
.spawn()
.await
.context("Starting the RPC server")?;
info!("📡 HTTP-RPC server started on: {}", local_addr);
rpc_handle
{
Ok((rpc_handle, on)) => {
info!(%on, "📡 RPC server started");
rpc_handle
}
Err(error) => tokio::task::spawn(std::future::ready(Err(
error.context("RPC server failed to start")
))),
}
} else {
tokio::spawn(std::future::pending())
};
Expand Down

0 comments on commit b5665cf

Please sign in to comment.