From 88a7ecce0dcf36da134d5cd552c5147d856c6b60 Mon Sep 17 00:00:00 2001 From: asonix Date: Tue, 29 Sep 2020 20:03:12 -0500 Subject: [PATCH] Use spawn blocking instead of block in place --- http-signature-normalization-reqwest/Cargo.toml | 4 ++-- http-signature-normalization-reqwest/src/digest/mod.rs | 7 ++++++- http-signature-normalization-reqwest/src/lib.rs | 3 +++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/http-signature-normalization-reqwest/Cargo.toml b/http-signature-normalization-reqwest/Cargo.toml index 402778d..d2f848e 100644 --- a/http-signature-normalization-reqwest/Cargo.toml +++ b/http-signature-normalization-reqwest/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "http-signature-normalization-reqwest" description = "An HTTP Signatures library that leaves the signing to you" -version = "0.1.1" +version = "0.1.2" authors = ["asonix "] license-file = "LICENSE" readme = "README.md" @@ -31,7 +31,7 @@ reqwest = "0.10.8" sha2 = { version = "0.9", optional = true } sha3 = { version = "0.9", optional = true } thiserror = "1.0" -tokio = { version = "0.2", default-features = false, features = ["rt-threaded", "blocking"], optional = true } +tokio = { version = "0.2", default-features = false, features = ["blocking"], optional = true } [dev-dependencies] pretty_env_logger = "0.4" diff --git a/http-signature-normalization-reqwest/src/digest/mod.rs b/http-signature-normalization-reqwest/src/digest/mod.rs index 53b6e74..3c475d1 100644 --- a/http-signature-normalization-reqwest/src/digest/mod.rs +++ b/http-signature-normalization-reqwest/src/digest/mod.rs @@ -73,7 +73,12 @@ impl SignExt for RequestBuilder { Self: Sized, { Box::pin(async move { - let digest = tokio::task::block_in_place(|| digest.compute(v.as_ref())); + let (v, digest) = tokio::task::spawn_blocking(move || { + let digest = digest.compute(v.as_ref()); + (v, digest) + }) + .await + .map_err(|_| SignError::Canceled)?; let c = self .header("Digest", format!("{}={}", D::NAME, digest)) diff --git a/http-signature-normalization-reqwest/src/lib.rs b/http-signature-normalization-reqwest/src/lib.rs index c7622fd..80819cd 100644 --- a/http-signature-normalization-reqwest/src/lib.rs +++ b/http-signature-normalization-reqwest/src/lib.rs @@ -70,6 +70,9 @@ pub enum SignError { #[error("Cannot sign request with body already present")] BodyPresent, + + #[error("Panic in spawn blocking")] + Canceled, } impl Config {