Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make daemon loop over coordinator connection to make it possible to create a system service awaiting coordinator connection #689

Merged
merged 1 commit into from
Oct 13, 2024
Merged
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
23 changes: 19 additions & 4 deletions binaries/daemon/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ use dora_message::{
daemon_to_coordinator::{CoordinatorRequest, DaemonCoordinatorReply, DaemonRegisterRequest},
};
use eyre::{eyre, Context};
use std::{io::ErrorKind, net::SocketAddr};
use std::{io::ErrorKind, net::SocketAddr, time::Duration};
use tokio::{
net::TcpStream,
sync::{mpsc, oneshot},
time::sleep,
};
use tokio_stream::{wrappers::ReceiverStream, Stream};
use tracing::warn;

const DAEMON_COORDINATOR_RETRY_INTERVAL: std::time::Duration = Duration::from_secs(1);

#[derive(Debug)]
pub struct CoordinatorEvent {
Expand All @@ -28,9 +32,20 @@ pub async fn register(
listen_port: u16,
clock: &HLC,
) -> eyre::Result<impl Stream<Item = Timestamped<CoordinatorEvent>>> {
let mut stream = TcpStream::connect(addr)
.await
.wrap_err("failed to connect to dora-coordinator")?;
let mut stream = loop {
match TcpStream::connect(addr)
.await
.wrap_err("failed to connect to dora-coordinator")
{
Err(err) => {
warn!("Could not connect to: {addr}, with error: {err}. Retring in {DAEMON_COORDINATOR_RETRY_INTERVAL:#?}..");
sleep(DAEMON_COORDINATOR_RETRY_INTERVAL).await;
}
Ok(stream) => {
break stream;
}
};
};
stream
.set_nodelay(true)
.wrap_err("failed to set TCP_NODELAY")?;
Expand Down
Loading