Skip to content

Commit 879adef

Browse files
authored
Merge pull request #186 from dfinity/shiling/router
feat: Block startup until route provider is healthy
2 parents 6177361 + 13d76e6 commit 879adef

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/routing/ic/route_provider.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{sync::Arc, time::Duration};
22

33
use anyhow::anyhow;
44
use derive_new::new;
@@ -13,7 +13,8 @@ use ic_bn_lib::ic_agent::agent::{
1313
},
1414
};
1515
use ic_bn_lib_common::{principal, traits::Healthy};
16-
use tracing::info;
16+
use tokio::time::{sleep, timeout};
17+
use tracing::{info, warn};
1718
use url::Url;
1819

1920
use crate::{
@@ -96,5 +97,17 @@ pub async fn setup_route_provider(
9697
Arc::new(RoundRobinRouteProvider::new(urls_str)?)
9798
};
9899

100+
let wrapper = RouteProviderWrapper::new(route_provider.clone());
101+
if timeout(Duration::from_secs(120), async {
102+
while !wrapper.healthy() {
103+
sleep(Duration::from_secs(1)).await;
104+
}
105+
})
106+
.await
107+
.is_err()
108+
{
109+
warn!("Route provider did not become healthy within 2 minutes, continuing anyway");
110+
}
111+
99112
Ok(route_provider)
100113
}

0 commit comments

Comments
 (0)