diff --git a/src/scheduler.rs b/src/scheduler.rs index 9b6b1993c..d51ad7aba 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -57,7 +57,9 @@ async fn inbox_loop(ctx: Context, inbox_handlers: ImapConnectionHandlers) { shutdown_sender, } = inbox_handlers; + let ctx1 = ctx.clone(); let fut = async move { + let ctx = ctx1; if let Err(err) = connection.connect_configured(&ctx).await { error!(ctx, "{}", err); return; @@ -106,6 +108,7 @@ async fn inbox_loop(ctx: Context, inbox_handlers: ImapConnectionHandlers) { } }; + info!(ctx, "Shutting down inbox loop"); fut.race(stop_receiver.recv().map(|_| ())).await; shutdown_sender.send(()).await; } @@ -201,7 +204,7 @@ async fn smtp_loop(ctx: Context, smtp_handlers: SmtpConnectionHandlers) { } }; - fut.race(stop_receiver.recv()).await; + fut.race(stop_receiver.recv()).await.ok(); shutdown_sender.send(()).await; } @@ -362,7 +365,7 @@ impl ConnectionState { // Trigger shutdown of the run loop. self.stop_sender.send(()).await; // Wait for a notification that the run loop has been shutdown. - self.shutdown_receiver.recv().await; + self.shutdown_receiver.recv().await.ok(); } async fn interrupt(&self) { diff --git a/src/sql.rs b/src/sql.rs index 0d84580e5..99dab7b06 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -181,7 +181,7 @@ impl Sql { let pool = lock.as_ref().ok_or_else(|| Error::SqlNoConnection)?; let conn = pool.get()?; - let res = async_std::task::spawn_blocking(move || g(conn)).await; + let res = g(conn); self.in_use.remove(); res @@ -419,7 +419,10 @@ impl Sql { let bt = backtrace::Backtrace::new(); eprintln!("old query: {}", query); eprintln!("Connection is already used from this thread: {:?}", bt); - panic!("Connection is already used from this thread"); + panic!( + "Connection is already used from this thread: trying to execute {}", + stmt.as_ref() + ); } self.in_use.set(stmt.as_ref().to_string());