Skip to content

Commit

Permalink
fix(network/discovery): use delay instead of sleep in main loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Erigara authored and loyd committed Feb 12, 2025
1 parent f204a2b commit 9178206
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions elfo-network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tracing::{debug, error, info, warn};
use elfo_core::{
message, msg, scope, tracing::TraceId, AnyMessage, Envelope, Message, MoveOwnership,
RestartPolicy, _priv::MessageKind, addr::GroupNo, messages::ConfigUpdated, stream::Stream,
RestartParams, Topology,
time::Delay, RestartParams, Topology,
};

use crate::{
Expand Down Expand Up @@ -72,6 +72,12 @@ struct ControlConnectionFailed {
transport: Option<Transport>,
}

#[message]
struct DelayReconnect {
role: ConnectionRole,
transport: Transport,
}

pub(super) struct Discovery {
cfg: config::Config,
ctx: NetworkContext,
Expand Down Expand Up @@ -115,13 +121,22 @@ impl Discovery {
msg @ ConnectionAccepted => self.on_connection_accepted(msg),
msg @ ConnectionRejected => self.on_connection_rejected(msg),
msg @ DataConnectionFailed => {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
let role = ConnectionRole::Data(internode::SwitchToData {
my_group_no: msg.local,
your_group_no: msg.remote.1,
initial_window: INITIAL_WINDOW_SIZE,
});
self.open_connection(&msg.transport, role);
self.ctx.attach(Delay::new(
// TODO: config param?
Duration::from_secs(1),
DelayReconnect {
role,
transport: msg.transport,
},
));
}
msg @ DelayReconnect => {
self.open_connection(&msg.transport, msg.role);
}
msg @ ControlConnectionFailed => {
if let Some(transport) = msg.transport {
Expand Down

0 comments on commit 9178206

Please sign in to comment.