avoid looping periphery client error

This commit is contained in:
mbecker20
2025-09-21 02:12:02 -07:00
parent 6f3703acfb
commit 2a065edcf1
3 changed files with 17 additions and 2 deletions

View File

@@ -39,17 +39,25 @@ pub async fn handler(
info!("Initiating outbound connection to {url}");
let mut already_logged_connection_error = false;
let mut already_logged_login_error = false;
loop {
let (socket, accept) =
match connect_websocket(&core_endpoint).await {
Ok(res) => res,
Err(e) => {
warn!("{e:#}");
if !already_logged_connection_error {
warn!("{e:#}");
already_logged_connection_error = true;
}
tokio::time::sleep(Duration::from_secs(5)).await;
continue;
}
};
already_logged_connection_error = false;
info!("Connected to core connection websocket");
let connection_identifiers = ConnectionIdentifiers {
@@ -64,10 +72,14 @@ pub async fn handler(
connection_identifiers,
"TEST",
&mut write_receiver,
|| already_logged_login_error = false,
)
.await
{
warn!("Failed to login | {e:#}");
if !already_logged_login_error {
warn!("Failed to login | {e:#}");
already_logged_login_error = true;
}
tokio::time::sleep(Duration::from_secs(5)).await;
continue;
};

View File

@@ -60,8 +60,10 @@ async fn handle_websocket<L: LoginFlow>(
connection_identifiers: ConnectionIdentifiers<'_>,
private_key: &str,
write_receiver: &mut BufferedReceiver<Bytes>,
mut on_login_success: impl FnMut(),
) -> anyhow::Result<()> {
L::login(&mut socket, connection_identifiers, private_key).await?;
on_login_success();
info!("Logged in to core connection websocket");

View File

@@ -95,6 +95,7 @@ async fn handler(
connection_identifiers,
"TEST",
&mut write_receiver,
|| {},
)
.await
{