improve logging and avoid race

This commit is contained in:
dignifiedquire
2020-03-23 19:49:37 +01:00
parent 01b88f876e
commit 69f1e1753c
2 changed files with 10 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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());