From a5aafef14e4d1c4a1938238a0d7facb3750cbca0 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Tue, 17 Oct 2023 14:57:07 +0200 Subject: [PATCH] fix false clippy beta warning: this MutexGuard is held across an await point (#22) fixes https://github.com/neondatabase/tokio-epoll-uring/issues --- tokio-epoll-uring/src/system/completion.rs | 38 +++++++++++++--------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/tokio-epoll-uring/src/system/completion.rs b/tokio-epoll-uring/src/system/completion.rs index f022d54..a12c05b 100644 --- a/tokio-epoll-uring/src/system/completion.rs +++ b/tokio-epoll-uring/src/system/completion.rs @@ -201,25 +201,31 @@ async fn poller_task( .unwrap() .block_on(async move { let poller = poller_clone; - let poller_guard = poller.lock().unwrap(); - match &poller_guard.state { - PollerState::RunningInThread(_) - | PollerState::ShuttingDownPreemptible(_, _) => { - drop(poller_guard); - if let Some(tx) = poller_switch_to_thread_done { - // receiver must ensure that clone doesn't outlive the try_unwrap during shutdown - tx.send(Arc::clone(&poller)).ok().unwrap(); + { + let poller_guard = poller.lock().unwrap(); + match &poller_guard.state { + PollerState::RunningInThread(_) + | PollerState::ShuttingDownPreemptible(_, _) => { + drop(poller_guard); + // Code continues below, outside of the scope that + // holds poller_guard. The control flow needs to be this + // weird to make clippy happy: + // https://rust-lang.github.io/rust-clippy/master/index.html#await_holding_lock + } + PollerState::RunningInTask(_) + | PollerState::ShuttingDownNoMorePreemptible + | PollerState::ShutDown => { + unreachable!("unexpected state: {:?}", poller_guard.state) } - poller_impl(poller, None, shutdown_loop_reached.clone()) - .instrument(info_span!("poller_thread", system=%id)) - .await - } - PollerState::RunningInTask(_) - | PollerState::ShuttingDownNoMorePreemptible - | PollerState::ShutDown => { - unreachable!("unexpected state: {:?}", poller_guard.state) } } + if let Some(tx) = poller_switch_to_thread_done { + // receiver must ensure that clone doesn't outlive the try_unwrap during shutdown + tx.send(Arc::clone(&poller)).ok().unwrap(); + } + poller_impl(poller, None, shutdown_loop_reached.clone()) + .instrument(info_span!("poller_thread", system=%id)) + .await }) }) .unwrap();