Only close listener connection on failure if it has been open for

a long time. This will protect against the case where the message
itself is the cause of the problem.
This commit is contained in:
Condorra 2022-12-24 13:57:41 +11:00
parent 729a218b36
commit ac10d7db84

View File

@ -12,6 +12,7 @@ use std::sync::Arc;
use uuid::Uuid;
use std::collections::BTreeMap;
use crate::DResult;
use std::time::Instant;
#[derive(Debug)]
pub struct ListenerSend {
@ -65,6 +66,7 @@ where
}
}
let connected_at = Instant::now();
let (sender, mut receiver) = mpsc::channel(1);
listener_map.lock().await.insert(listener_id, sender);
@ -129,11 +131,17 @@ where
match handle_fut.await {
Ok(_) => {}
Err(e) => {
// On the assumption errors that get here are bad enough that they are a
// problem with the system rather than the message, so we want to log and
// retry later.
warn!("Error from message handler - closing listener connection: {}", e);
break 'listener_loop;
if connected_at.elapsed() > std::time::Duration::from_secs(60) {
// On the assumption errors that get here are bad enough that they are a
// problem with the system rather than the message, so we want to log and
// retry later.
warn!("Error from message handler - closing listener connection: {}", e);
break 'listener_loop;
} else {
warn!("Error from message handler, but we only just connected, so \
acknowledging it anyway as a safety measure against reconnect \
loops: {}", e);
}
}
}