Page MenuHomePhabricator

D13603.diff
No OneTemporary

D13603.diff

diff --git a/services/tunnelbroker/src/amqp.rs b/services/tunnelbroker/src/amqp.rs
--- a/services/tunnelbroker/src/amqp.rs
+++ b/services/tunnelbroker/src/amqp.rs
@@ -4,7 +4,7 @@
use std::sync::Arc;
use std::time::Duration;
use tokio::sync::RwLock;
-use tracing::{debug, error, info};
+use tracing::{debug, error, info, warn};
use crate::constants::error_types;
use crate::CONFIG;
@@ -110,6 +110,25 @@
Ok(Self { inner })
}
+ pub async fn new_channel(&self) -> Result<lapin::Channel, lapin::Error> {
+ if !self.is_connected().await {
+ warn!("AMQP disconnected while retrieving channel");
+ self.reset_conn().await?;
+ }
+ self.inner.read().await.conn.create_channel().await
+ }
+
+ async fn reset_conn(&self) -> Result<(), lapin::Error> {
+ let mut inner = self.inner.write().await;
+ if !inner.is_connected() {
+ debug!("Resetting AMQP connection...");
+ let new_conn = ConnectionInner::new().await?;
+ *inner = new_conn;
+ info!("AMQP Connection restored.");
+ }
+ Ok(())
+ }
+
async fn is_connected(&self) -> bool {
self.inner.read().await.is_connected()
}

File Metadata

Mime Type
text/plain
Expires
Mon, Nov 25, 4:41 AM (22 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2578368
Default Alt Text
D13603.diff (1 KB)

Event Timeline