mirror of
https://github.com/chatmail/core.git
synced 2026-05-23 00:36:32 +03:00
improve logging and avoid race
This commit is contained in:
@@ -57,7 +57,9 @@ async fn inbox_loop(ctx: Context, inbox_handlers: ImapConnectionHandlers) {
|
|||||||
shutdown_sender,
|
shutdown_sender,
|
||||||
} = inbox_handlers;
|
} = inbox_handlers;
|
||||||
|
|
||||||
|
let ctx1 = ctx.clone();
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
|
let ctx = ctx1;
|
||||||
if let Err(err) = connection.connect_configured(&ctx).await {
|
if let Err(err) = connection.connect_configured(&ctx).await {
|
||||||
error!(ctx, "{}", err);
|
error!(ctx, "{}", err);
|
||||||
return;
|
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;
|
fut.race(stop_receiver.recv().map(|_| ())).await;
|
||||||
shutdown_sender.send(()).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;
|
shutdown_sender.send(()).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +365,7 @@ impl ConnectionState {
|
|||||||
// Trigger shutdown of the run loop.
|
// Trigger shutdown of the run loop.
|
||||||
self.stop_sender.send(()).await;
|
self.stop_sender.send(()).await;
|
||||||
// Wait for a notification that the run loop has been shutdown.
|
// 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) {
|
async fn interrupt(&self) {
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ impl Sql {
|
|||||||
let pool = lock.as_ref().ok_or_else(|| Error::SqlNoConnection)?;
|
let pool = lock.as_ref().ok_or_else(|| Error::SqlNoConnection)?;
|
||||||
let conn = pool.get()?;
|
let conn = pool.get()?;
|
||||||
|
|
||||||
let res = async_std::task::spawn_blocking(move || g(conn)).await;
|
let res = g(conn);
|
||||||
self.in_use.remove();
|
self.in_use.remove();
|
||||||
|
|
||||||
res
|
res
|
||||||
@@ -419,7 +419,10 @@ impl Sql {
|
|||||||
let bt = backtrace::Backtrace::new();
|
let bt = backtrace::Backtrace::new();
|
||||||
eprintln!("old query: {}", query);
|
eprintln!("old query: {}", query);
|
||||||
eprintln!("Connection is already used from this thread: {:?}", bt);
|
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());
|
self.in_use.set(stmt.as_ref().to_string());
|
||||||
|
|||||||
Reference in New Issue
Block a user