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

[bugfix] Prevent typed unix socket client from looping forever on failure to connect #796

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
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
18 changes: 10 additions & 8 deletions plane/src/typed_unix_socket/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{get_quick_backoff, WrappedMessage};
use crate::util::{random_token, GuardHandle};
use super::WrappedMessage;
use crate::util::{random_token, ExponentialBackoff, GuardHandle};
use anyhow::{Error, Result};
use dashmap::DashMap;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -47,14 +47,11 @@ where
let response_map = Arc::clone(&response_map);
let event_tx = event_tx.clone();
GuardHandle::new(async move {
let mut backoff = get_quick_backoff();
loop {
let Ok(stream) = timeout(CONNECT_TIMEOUT, connect(&socket_path)).await else {
tracing::error!("Timeout connecting to server");
backoff.wait().await;
continue;
tracing::error!("Timeout connecting to server; shutting down");
break;
};
backoff.reset();
if handle_connection(stream, rx, Arc::clone(&response_map), event_tx.clone())
.await
.is_ok()
Expand Down Expand Up @@ -109,7 +106,12 @@ where

async fn connect<P: AsRef<Path>>(socket_path: P) -> UnixStream {
let socket_path = socket_path.as_ref().to_path_buf();
let mut backoff = get_quick_backoff();
let mut backoff = ExponentialBackoff::new(
chrono::Duration::milliseconds(10),
chrono::Duration::seconds(1),
1.5,
chrono::Duration::seconds(1),
);
loop {
match UnixStream::connect(&socket_path).await {
Ok(stream) => return stream,
Expand Down
11 changes: 0 additions & 11 deletions plane/src/typed_unix_socket/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::util::ExponentialBackoff;
use chrono::Duration;
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::PathBuf;
Expand All @@ -15,15 +13,6 @@ pub struct WrappedMessage<T> {
pub message: T,
}

fn get_quick_backoff() -> ExponentialBackoff {
ExponentialBackoff::new(
Duration::milliseconds(10),
Duration::milliseconds(100),
1.1,
Duration::milliseconds(100),
)
}

pub struct SocketPath(pub PathBuf);

impl Drop for SocketPath {
Expand Down
Loading