diff --git a/src/cloudfront.rs b/src/cloudfront.rs index 9e351d7c54..fbf8ac53d7 100644 --- a/src/cloudfront.rs +++ b/src/cloudfront.rs @@ -5,12 +5,11 @@ use aws_sdk_cloudfront::types::{InvalidationBatch, Paths}; use aws_sdk_cloudfront::{Client, Config}; use retry::delay::{jitter, Exponential}; use retry::OperationResult; -use std::panic::AssertUnwindSafe; use std::time::Duration; use tokio::runtime::Runtime; pub struct CloudFront { - client: AssertUnwindSafe, + client: Client, distribution_id: String, } @@ -27,7 +26,7 @@ impl CloudFront { .credentials_provider(credentials) .build(); - let client = AssertUnwindSafe(Client::from_conf(config)); + let client = Client::from_conf(config); Some(Self { client, diff --git a/src/worker/environment.rs b/src/worker/environment.rs index 4054878720..4186560392 100644 --- a/src/worker/environment.rs +++ b/src/worker/environment.rs @@ -4,15 +4,14 @@ use crate::storage::Storage; use crate::worker::swirl::PerformError; use crates_io_index::Repository; use reqwest::blocking::Client; -use std::panic::AssertUnwindSafe; use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; pub struct Environment { index: Mutex, - http_client: AssertUnwindSafe, + http_client: Client, cloudfront: Option, fastly: Option, - pub storage: AssertUnwindSafe>, + pub storage: Arc, } impl Environment { @@ -25,10 +24,10 @@ impl Environment { ) -> Self { Self { index: Mutex::new(index), - http_client: AssertUnwindSafe(http_client), + http_client, cloudfront, fastly, - storage: AssertUnwindSafe(storage), + storage, } } diff --git a/src/worker/swirl/runner.rs b/src/worker/swirl/runner.rs index a99875d283..d5cb0a5460 100644 --- a/src/worker/swirl/runner.rs +++ b/src/worker/swirl/runner.rs @@ -7,7 +7,7 @@ use parking_lot::RwLock; use std::any::Any; use std::collections::HashMap; use std::error::Error; -use std::panic::{catch_unwind, AssertUnwindSafe, PanicInfo, UnwindSafe}; +use std::panic::{catch_unwind, AssertUnwindSafe, PanicInfo}; use std::sync::mpsc::{sync_channel, SyncSender}; use std::sync::Arc; use std::time::Duration; @@ -29,7 +29,7 @@ fn runnable( } /// The core runner responsible for locking and running jobs -pub struct Runner { +pub struct Runner { connection_pool: DieselPool, thread_pool: ThreadPool, job_registry: Arc>>>, @@ -37,7 +37,7 @@ pub struct Runner { job_start_timeout: Duration, } -impl Runner { +impl Runner { pub fn new(connection_pool: DieselPool, environment: Context) -> Self { Self { connection_pool, @@ -110,7 +110,7 @@ impl Runner { fn run_single_job(&self, sender: SyncSender) { use diesel::result::Error::RollbackTransaction; - let job_registry = AssertUnwindSafe(self.job_registry.clone()); + let job_registry = self.job_registry.clone(); let environment = self.environment.clone(); // The connection may not be `Send` so we need to clone the pool instead @@ -155,11 +155,8 @@ impl Runner { || { conn.transaction(|conn| { let pool = pool.to_real_pool(); - let state = AssertUnwindSafe(PerformState { conn, pool }); - catch_unwind(|| { - // Ensure the whole `AssertUnwindSafe(_)` is moved - let state = state; - + let state = PerformState { conn, pool }; + catch_unwind(AssertUnwindSafe(|| { let job_registry = job_registry.read(); let run_task_fn = job_registry.get(&job.job_type).ok_or_else(|| { @@ -169,8 +166,8 @@ impl Runner { )) })?; - run_task_fn(environment, state.0, job.data) - }) + run_task_fn(environment, state, job.data) + })) .map_err(|e| try_to_extract_panic_info(&e)) }) // TODO: Replace with flatten() once that stabilizes @@ -294,7 +291,6 @@ mod tests { use crates_io_test_db::TestDatabase; use diesel::r2d2; use diesel::r2d2::ConnectionManager; - use std::panic::AssertUnwindSafe; use std::sync::{Arc, Barrier}; fn job_exists(id: i64, conn: &mut PgConnection) -> bool { @@ -323,8 +319,8 @@ mod tests { fn jobs_are_locked_when_fetched() { #[derive(Clone)] struct TestContext { - job_started_barrier: Arc>, - assertions_finished_barrier: Arc>, + job_started_barrier: Arc, + assertions_finished_barrier: Arc, } #[derive(Serialize, Deserialize)] @@ -344,8 +340,8 @@ mod tests { let test_database = TestDatabase::new(); let test_context = TestContext { - job_started_barrier: Arc::new(AssertUnwindSafe(Barrier::new(2))), - assertions_finished_barrier: Arc::new(AssertUnwindSafe(Barrier::new(2))), + job_started_barrier: Arc::new(Barrier::new(2)), + assertions_finished_barrier: Arc::new(Barrier::new(2)), }; let runner = @@ -409,7 +405,7 @@ mod tests { fn failed_jobs_do_not_release_lock_before_updating_retry_time() { #[derive(Clone)] struct TestContext { - job_started_barrier: Arc>, + job_started_barrier: Arc, } #[derive(Serialize, Deserialize)] @@ -428,7 +424,7 @@ mod tests { let test_database = TestDatabase::new(); let test_context = TestContext { - job_started_barrier: Arc::new(AssertUnwindSafe(Barrier::new(2))), + job_started_barrier: Arc::new(Barrier::new(2)), }; let runner = @@ -495,7 +491,7 @@ mod tests { assert_eq!(tries, 1); } - fn runner( + fn runner( database_url: &str, context: Context, ) -> Runner {