From 380c35beb96e953327a2b82fcbe9005549770828 Mon Sep 17 00:00:00 2001 From: Pavel Kirilin <win10@list.ru> Date: Thu, 24 Feb 2022 01:26:37 +0400 Subject: [PATCH] Fixed random freezes. (#43) Signed-off-by: Pavel Kirilin <win10@list.ru> --- Cargo.lock | 240 ------------------------- Cargo.toml | 9 +- src/info_storages/file_info_storage.rs | 7 +- src/notifiers/http_notifier.rs | 6 +- src/storages/file_storage.rs | 19 +- 5 files changed, 17 insertions(+), 264 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8145b3b..1bbab12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,112 +312,6 @@ version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a1bb320f97e6edf9f756bf015900038e43c7700e059688e5724a928c8f3b8d5" -[[package]] -name = "async-channel" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2114d64672151c0c5eaa5e131ec84a74f06e1e559830dabba01ca30605d66319" -dependencies = [ - "concurrent-queue", - "event-listener", - "futures-core", -] - -[[package]] -name = "async-executor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "871f9bb5e0a22eeb7e8cf16641feb87c9dc67032ccf8ff49e772eb9941d3a965" -dependencies = [ - "async-task", - "concurrent-queue", - "fastrand", - "futures-lite", - "once_cell", - "slab", -] - -[[package]] -name = "async-global-executor" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9586ec52317f36de58453159d48351bc244bc24ced3effc1fce22f3d48664af6" -dependencies = [ - "async-channel", - "async-executor", - "async-io", - "async-mutex", - "blocking", - "futures-lite", - "num_cpus", - "once_cell", - "tokio", -] - -[[package]] -name = "async-io" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a811e6a479f2439f0c04038796b5cfb3d2ad56c230e0f2d3f7b04d68cfee607b" -dependencies = [ - "concurrent-queue", - "futures-lite", - "libc", - "log", - "once_cell", - "parking", - "polling", - "slab", - "socket2", - "waker-fn", - "winapi", -] - -[[package]] -name = "async-lock" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6a8ea61bf9947a1007c5cada31e647dbc77b103c679858150003ba697ea798b" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-mutex" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-std" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8056f1455169ab86dd47b47391e4ab0cbd25410a70e9fe675544f49bafaf952" -dependencies = [ - "async-channel", - "async-global-executor", - "async-io", - "async-lock", - "crossbeam-utils", - "futures-channel", - "futures-core", - "futures-io", - "futures-lite", - "gloo-timers", - "kv-log-macro", - "log", - "memchr", - "num_cpus", - "once_cell", - "pin-project-lite", - "pin-utils", - "slab", - "wasm-bindgen-futures", -] - [[package]] name = "async-task" version = "4.1.0" @@ -444,12 +338,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "atomic-waker" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" - [[package]] name = "atty" version = "0.2.14" @@ -560,20 +448,6 @@ dependencies = [ "byte-tools", ] -[[package]] -name = "blocking" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046e47d4b2d391b1f6f8b407b1deb8dee56c1852ccd868becf2710f601b5f427" -dependencies = [ - "async-channel", - "async-task", - "atomic-waker", - "fastrand", - "futures-lite", - "once_cell", -] - [[package]] name = "brotli" version = "3.3.3" @@ -639,12 +513,6 @@ dependencies = [ "bytes", ] -[[package]] -name = "cache-padded" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" - [[package]] name = "cc" version = "1.0.72" @@ -714,15 +582,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "concurrent-queue" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" -dependencies = [ - "cache-padded", -] - [[package]] name = "const-oid" version = "0.6.2" @@ -867,16 +726,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "ctor" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccc0a48a9b826acdf4028595adc9db92caea352f7af011a3034acd172a52a0aa" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "dashmap" version = "4.0.2" @@ -994,12 +843,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "event-listener" -version = "2.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71" - [[package]] name = "fake-simd" version = "0.1.2" @@ -1151,21 +994,6 @@ version = "0.3.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" -[[package]] -name = "futures-lite" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" -dependencies = [ - "fastrand", - "futures-core", - "futures-io", - "memchr", - "parking", - "pin-project-lite", - "waker-fn", -] - [[package]] name = "futures-macro" version = "0.3.21" @@ -1243,18 +1071,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "gloo-timers" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d12a7f4e95cfe710f1d624fb1210b7d961a5fb05c4fd942f4feab06e61f590e" -dependencies = [ - "futures-channel", - "futures-core", - "js-sys", - "wasm-bindgen", -] - [[package]] name = "h2" version = "0.3.11" @@ -1524,15 +1340,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "kv-log-macro" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" -dependencies = [ - "log", -] - [[package]] name = "language-tags" version = "0.3.2" @@ -1622,7 +1429,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ "cfg-if", - "value-bag", ] [[package]] @@ -1934,12 +1740,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "parking" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" - [[package]] name = "parking_lot" version = "0.11.2" @@ -2136,19 +1936,6 @@ version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe" -[[package]] -name = "polling" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "685404d509889fade3e86fe3a5803bca2ec09b0c0778d5ada6ec8bf7a8de5259" -dependencies = [ - "cfg-if", - "libc", - "log", - "wepoll-ffi", - "winapi", -] - [[package]] name = "ppv-lite86" version = "0.2.16" @@ -2591,13 +2378,11 @@ dependencies = [ "actix-files", "actix-rt", "actix-web", - "async-std", "async-trait", "base64", "chrono", "derive_more", "fern", - "futures", "httptest", "lapin", "lazy_static", @@ -3472,16 +3257,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "value-bag" -version = "1.0.0-alpha.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79923f7731dc61ebfba3633098bf3ac533bbd35ccd8c57e7088d9a5eebe0263f" -dependencies = [ - "ctor", - "version_check", -] - [[package]] name = "vcpkg" version = "0.2.15" @@ -3500,12 +3275,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "waker-fn" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" - [[package]] name = "want" version = "0.3.0" @@ -3617,15 +3386,6 @@ dependencies = [ "webpki", ] -[[package]] -name = "wepoll-ffi" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" -dependencies = [ - "cc", -] - [[package]] name = "whoami" version = "1.2.1" diff --git a/Cargo.toml b/Cargo.toml index a44831d..5255413 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,10 +31,6 @@ version = "0.6.0-beta.13" [dependencies.actix-web] version = "^4.0.0-beta.20" -[dependencies.async-std] -features = ["tokio1"] -version = "^1.10.0" - [dependencies.chrono] features = ["serde"] version = "^0.4.19" @@ -48,10 +44,6 @@ version = "^0.99.9" features = ["colored"] version = "0.6.0" -[dependencies.futures] -features = ["executor"] -version = "^0.3.19" - [dependencies.lapin] optional = true version = "^1.9.0" @@ -120,5 +112,6 @@ httptest = "0.15.4" [profile] [profile.release] lto = true +panic = "abort" opt-level = "z" codegen-units = 1 diff --git a/src/info_storages/file_info_storage.rs b/src/info_storages/file_info_storage.rs index bafa5bc..08f977b 100644 --- a/src/info_storages/file_info_storage.rs +++ b/src/info_storages/file_info_storage.rs @@ -1,10 +1,9 @@ use std::path::PathBuf; -use async_std::fs::{read_to_string, remove_file, DirBuilder, OpenOptions}; use async_trait::async_trait; -use futures::io::BufWriter; -use futures::AsyncWriteExt; use log::error; +use tokio::fs::{read_to_string, remove_file, DirBuilder, OpenOptions}; +use tokio::io::{AsyncWriteExt, BufWriter}; use crate::errors::{RustusError, RustusResult}; use crate::info_storages::{FileInfo, InfoStorage}; @@ -48,7 +47,7 @@ impl InfoStorage for FileInfoStorage { })?; let mut writer = BufWriter::new(file); writer - .write_all( + .write( serde_json::to_string(&file_info) .map_err(|err| { error!("{:#?}", err); diff --git a/src/notifiers/http_notifier.rs b/src/notifiers/http_notifier.rs index 2e71004..36956d5 100644 --- a/src/notifiers/http_notifier.rs +++ b/src/notifiers/http_notifier.rs @@ -4,7 +4,6 @@ use crate::notifiers::{Hook, Notifier}; use actix_web::http::header::HeaderMap; use async_trait::async_trait; -use futures::future::try_join_all; use log::debug; use reqwest::Client; use std::time::Duration; @@ -56,9 +55,8 @@ impl Notifier for HttpNotifier { } request.body(message.clone()).send() }); - let responses = try_join_all(requests_vec).await?; - for resp in responses { - resp.error_for_status()?; + for response in requests_vec { + response.await?.error_for_status()?; } Ok(()) } diff --git a/src/storages/file_storage.rs b/src/storages/file_storage.rs index ba44819..607dbc1 100644 --- a/src/storages/file_storage.rs +++ b/src/storages/file_storage.rs @@ -1,18 +1,16 @@ use std::path::PathBuf; use actix_files::NamedFile; -use async_std::fs::{remove_file, DirBuilder, File, OpenOptions}; -use async_std::io::copy; use async_trait::async_trait; use log::error; +use tokio::fs::{remove_file, DirBuilder, OpenOptions}; +use tokio::io::{copy, AsyncWriteExt, BufWriter}; use crate::errors::{RustusError, RustusResult}; use crate::info_storages::FileInfo; use crate::storages::Storage; use crate::utils::dir_struct::dir_struct; use derive_more::Display; -use futures::io::BufWriter; -use futures::AsyncWriteExt; #[derive(Display)] #[display(fmt = "file_storage")] @@ -98,12 +96,14 @@ impl Storage for FileStorage { RustusError::UnableToWrite(err.to_string()) })?; let mut writer = BufWriter::new(file); - writer.write_all(bytes).await.map_err(|err| { + writer.write(bytes).await.map_err(|err| { + error!("{:?}", err); + RustusError::UnableToWrite(info.path.clone().unwrap()) + })?; + writer.flush().await.map_err(|err| { error!("{:?}", err); RustusError::UnableToWrite(info.path.clone().unwrap()) })?; - // Updating information about file. - writer.flush().await?; Ok(()) } @@ -144,7 +144,10 @@ impl Storage for FileStorage { if part.path.is_none() { return Err(RustusError::FileNotFound); } - let mut part_file = File::open(part.path.as_ref().unwrap()).await?; + let mut part_file = OpenOptions::new() + .read(true) + .open(part.path.as_ref().unwrap()) + .await?; copy(&mut part_file, &mut file).await?; } file.sync_data().await?; -- GitLab