Skip to content

Commit 8ef3c79

Browse files
committed
add connection timeout when connecting to the local broker
Resolves #3660 Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
1 parent 1d17950 commit 8ef3c79

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

crates/core/c8y_api/src/http_proxy.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,10 @@ impl C8yAuthRetriever {
386386
mqtt_config: &mqtt_channel::Config,
387387
topic_prefix: &TopicPrefix,
388388
) -> Result<SmartRestJwtResponse, JwtError> {
389-
let mut mqtt_con = Connection::new(mqtt_config).await?;
389+
let connection_timeout = Duration::from_secs(30);
390+
let mut mqtt_con = tokio::time::timeout(connection_timeout, Connection::new(mqtt_config))
391+
.await
392+
.map_err(|_| JwtError::MqttConnectionTimeout(connection_timeout))??;
390393
let pub_topic = format!("{}/s/uat", topic_prefix);
391394

392395
tokio::time::sleep(Duration::from_millis(20)).await;
@@ -471,6 +474,9 @@ pub enum JwtError {
471474

472475
#[error("No JWT token has been received")]
473476
NoJwtReceived,
477+
478+
#[error("Timed out after {0:?} when trying to connect to the local MQTT broker")]
479+
MqttConnectionTimeout(Duration),
474480
}
475481

476482
#[cfg(test)]

0 commit comments

Comments
 (0)