specify I/O timeout
We need to be a bit conservative here due to buffer bloat - in the upload case on a slow link, it can appear that no I/O is happening when a buffer is draining.
This commit is contained in:
parent
7f15d06c58
commit
06e00be985
@ -8,7 +8,7 @@ use crate::media::files::{
|
||||
add_file_from_ankiweb, data_for_file, mtime_as_i64, normalize_filename, AddedFile,
|
||||
};
|
||||
use crate::media::MediaManager;
|
||||
use crate::version;
|
||||
use crate::{sync::Timeouts, version};
|
||||
use bytes::Bytes;
|
||||
use reqwest::{multipart, Client, Response};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
@ -155,9 +155,11 @@ where
|
||||
host_number: u32,
|
||||
log: Logger,
|
||||
) -> MediaSyncer<'_, P> {
|
||||
let timeouts = Timeouts::new();
|
||||
let client = Client::builder()
|
||||
.connect_timeout(Duration::from_secs(30))
|
||||
.timeout(Duration::from_secs(60))
|
||||
.connect_timeout(Duration::from_secs(timeouts.connect_secs))
|
||||
.timeout(Duration::from_secs(timeouts.request_secs))
|
||||
.io_timeout(Duration::from_secs(timeouts.io_secs))
|
||||
.build()
|
||||
.unwrap();
|
||||
let endpoint = media_sync_endpoint(host_number);
|
||||
|
@ -72,14 +72,33 @@ struct SanityCheckIn {
|
||||
full: bool,
|
||||
}
|
||||
|
||||
pub struct Timeouts {
|
||||
pub connect_secs: u64,
|
||||
pub request_secs: u64,
|
||||
pub io_secs: u64,
|
||||
}
|
||||
|
||||
impl Timeouts {
|
||||
pub fn new() -> Self {
|
||||
Timeouts {
|
||||
connect_secs: 30,
|
||||
/// This is smaller than the I/O limit because it is just a
|
||||
/// default - some longer-running requests override it.
|
||||
request_secs: 60,
|
||||
io_secs: 300,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Serialize)]
|
||||
struct Empty {}
|
||||
|
||||
impl HTTPSyncClient {
|
||||
pub fn new(hkey: Option<String>, host_number: u32) -> HTTPSyncClient {
|
||||
let timeouts = Timeouts::new();
|
||||
let client = Client::builder()
|
||||
.connect_timeout(Duration::from_secs(30))
|
||||
.timeout(Duration::from_secs(60))
|
||||
.connect_timeout(Duration::from_secs(timeouts.connect_secs))
|
||||
.timeout(Duration::from_secs(timeouts.request_secs))
|
||||
.io_timeout(Duration::from_secs(timeouts.io_secs))
|
||||
.build()
|
||||
.unwrap();
|
||||
let skey = guid();
|
||||
|
@ -21,6 +21,7 @@ use flate2::write::GzEncoder;
|
||||
use flate2::Compression;
|
||||
use futures::StreamExt;
|
||||
use http_client::HTTPSyncClient;
|
||||
pub use http_client::Timeouts;
|
||||
use itertools::Itertools;
|
||||
use reqwest::{multipart, Client, Response};
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
|
Loading…
Reference in New Issue
Block a user