Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add timeouts for Client::reqwest calls [SYNC-3289] #329

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion autoendpoint/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use actix_web::{
use cadence::StatsdClient;
use fernet::MultiFernet;
use std::sync::Arc;
use std::time::Duration;

#[derive(Clone)]
pub struct ServerState {
Expand Down Expand Up @@ -51,7 +52,11 @@ impl Server {
settings.router_table_name.clone(),
settings.message_table_name.clone(),
)?);
let http = reqwest::Client::new();
let http = reqwest::ClientBuilder::new()
.connect_timeout(Duration::from_millis(settings.connection_timeout_millis))
.timeout(Duration::from_millis(settings.request_timeout_millis))
.build()
.expect("Could not generate request client");
let fcm_router = Arc::new(
FcmRouter::new(
settings.fcm.clone(),
Expand Down
5 changes: 5 additions & 0 deletions autoendpoint/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct Settings {
pub auth_keys: String,
pub human_logs: bool,

pub connection_timeout_millis: u64,
pub request_timeout_millis: u64,

pub statsd_host: Option<String>,
pub statsd_port: u16,
pub statsd_label: String,
Expand All @@ -53,6 +56,8 @@ impl Default for Settings {
crypto_keys: format!("[{}]", Fernet::generate_key()),
auth_keys: r#"["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB="]"#.to_string(),
human_logs: false,
connection_timeout_millis: 1000,
request_timeout_millis: 3000,
statsd_host: None,
statsd_port: 8125,
statsd_label: "autoendpoint".to_string(),
Expand Down