Skip to content

Commit 71d7ba4

Browse files
authored
Merge pull request #1298 from Phala-Network/poller-timeout
phat-poller: Fix fetch profiles timeout
2 parents 2557992 + 7e0b250 commit 71d7ba4

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

poller.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RUN mkdir -p build-out/
1717
RUN cp target/x86_64-unknown-linux-musl/release/phat-poller build-out/
1818
RUN strip build-out/phat-poller
1919

20-
FROM scratch
20+
FROM alpine
2121
WORKDIR /app
2222
COPY --from=builder /root/build-out/phat-poller .
2323
USER 1000:1000

standalone/phat-poller/src/app.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
time::Duration,
1313
};
1414

15-
use anyhow::{anyhow, Result};
15+
use anyhow::{anyhow, Result, Context};
1616
use phaxt::AccountId;
1717
use sp_core::{sr25519::Pair as KeyPair, H256};
1818
use tokio::task::JoinHandle;
@@ -297,8 +297,16 @@ impl App {
297297
info!("poll contracts begin");
298298
let start = Instant::now();
299299
self.state.lock().unwrap().last_poll_time = Some(start);
300-
if let Err(err) = self.poll_contracts().await {
301-
warn!("failed to poll contracts: {err}");
300+
let result =
301+
tokio::time::timeout(self.config.poll_timeout_overall, self.poll_contracts()).await;
302+
match result {
303+
Err(_) => {
304+
warn!("poll contracts timeout");
305+
}
306+
Ok(Err(err)) => {
307+
warn!("failed to poll contracts: {err}");
308+
}
309+
Ok(Ok(())) => {}
302310
}
303311
let rest_time = self.config.poll_interval.saturating_sub(start.elapsed());
304312
info!("{}ms elapsed", start.elapsed().as_millis());
@@ -332,17 +340,20 @@ impl App {
332340
info!(latency=?worker.latency().unwrap_or(Duration::MAX), " {}", worker.pubkey);
333341
}
334342
let worker = &top_workers[0];
335-
let contracts: Vec<(AccountId, ContractId)> =
343+
let contracts: Vec<(AccountId, ContractId)> = tokio::time::timeout(
344+
self.config.poll_timeout,
336345
pink_query::<_, crate::contracts::UserProfilesResponse>(
337346
&worker.pubkey,
338347
&worker.uri,
339348
self.config.factory_contract,
340349
SELECTOR_GET_USER_PROFILES,
341350
(),
342351
&self.config.caller,
343-
)
344-
.await?
345-
.or(Err(anyhow::anyhow!("query failed")))?;
352+
),
353+
)
354+
.await
355+
.context("Get profiles timeout")??
356+
.or(Err(anyhow::anyhow!("query failed")))?;
346357

347358
let mut poll_handles = Vec::with_capacity(contracts.len());
348359

standalone/phat-poller/src/args.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ pub struct RunArgs {
4949
#[arg(long, value_parser = parse_duration, default_value = "10s")]
5050
pub poll_timeout: Duration,
5151

52+
/// Contract poll timeout over all contracts
53+
#[arg(long, value_parser = parse_duration, default_value = "20s")]
54+
pub poll_timeout_overall: Duration,
55+
5256
/// Top n workers to be used to poll
5357
#[arg(long, default_value_t = 5)]
5458
pub use_top_workers: usize,

0 commit comments

Comments
 (0)