Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 17, 2024
1 parent 9b0d59f commit 42cb5d8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 0 additions & 1 deletion aw-sync/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ fn main() -> Result<(), Box<dyn Error>> {
// Start daemon
Commands::Daemon {} => {
info!("Starting daemon...");
// TODO: log any errors before re-throwing
daemon(&client)?;
}
// Perform basic sync
Expand Down
8 changes: 4 additions & 4 deletions aw-sync/src/sync_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ pub fn pull_all(client: &AwClient) -> Result<(), Box<dyn Error>> {
fn wait_for_server(socket_addr: &std::net::SocketAddr) -> Result<(), Box<dyn Error>> {
// Check if server is running with exponential backoff
let mut retry_delay = Duration::from_millis(100);
let max_retry_delay = Duration::from_secs(10);
let max_wait = Duration::from_secs(10);
let mut total_wait = Duration::from_secs(0);

while total_wait < max_retry_delay {
while total_wait < max_wait {
match TcpStream::connect_timeout(socket_addr, retry_delay) {
Ok(_) => break,
Err(_) => {
std::thread::sleep(retry_delay);
total_wait += retry_delay;
retry_delay = std::cmp::min(retry_delay * 2, max_retry_delay);
retry_delay *= 2;
}
}
}

if total_wait >= max_retry_delay {
if total_wait >= max_wait {
return Err(format!(
"Local server {} not running after 10 seconds of retrying",
socket_addr
Expand Down

0 comments on commit 42cb5d8

Please sign in to comment.