diff --git a/Cargo.lock b/Cargo.lock index c3949548f..eff2b7bae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -373,6 +373,7 @@ dependencies = [ "notify 4.0.15 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "params 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "path-slash 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "procfs 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 63b5df519..d9a0341b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,6 +46,7 @@ path-slash = "0.1.3" once_cell = { version = "1.4.0", features = ["parking_lot"] } base64 = "0.12.1" strum = { version = "0.18.0", features = ["derive"] } +parking_lot = "0.10.2" # Data serialization and deserialization serde = { version = "1.0", features = ["derive"] } diff --git a/src/storage/s3.rs b/src/storage/s3.rs index bfd6d7b3a..4d09a170e 100644 --- a/src/storage/s3.rs +++ b/src/storage/s3.rs @@ -4,6 +4,8 @@ use failure::Error; use futures::stream::{FuturesUnordered, Stream}; use futures::Future; use log::{error, warn}; +use once_cell::sync::Lazy; +use parking_lot::Mutex; use rusoto_core::region::Region; use rusoto_credential::DefaultCredentialsProvider; use rusoto_s3::{GetObjectRequest, PutObjectRequest, S3Client, S3}; @@ -16,6 +18,8 @@ mod test; pub(crate) use test::TestS3; pub(crate) static S3_BUCKET_NAME: &str = "rust-docs-rs"; +static S3_RUNTIME: Lazy> = + Lazy::new(|| Mutex::new(Runtime::new().expect("Failed to create S3 runtime"))); pub(crate) struct S3Backend { client: S3Client, @@ -63,16 +67,12 @@ impl S3Backend { } pub(super) fn start_storage_transaction(&self) -> Result { - Ok(S3StorageTransaction { - s3: self, - runtime: Runtime::new()?, - }) + Ok(S3StorageTransaction { s3: self }) } } pub(super) struct S3StorageTransaction<'a> { s3: &'a S3Backend, - runtime: Runtime, } impl<'a> StorageTransaction for S3StorageTransaction<'a> { @@ -100,7 +100,7 @@ impl<'a> StorageTransaction for S3StorageTransaction<'a> { } attempts += 1; - match self.runtime.block_on(futures.map(drop).collect()) { + match S3_RUNTIME.lock().block_on(futures.map(drop).collect()) { // this batch was successful, start another batch if there are still more files Ok(_) => break, Err(err) => { @@ -112,6 +112,7 @@ impl<'a> StorageTransaction for S3StorageTransaction<'a> { } } } + Ok(()) }