mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 10:56:29 +03:00
Use spawn() instead of block_on() again because it reportedly might lead to deadlocks
Also, fix some minor stuff
This commit is contained in:
@@ -337,7 +337,7 @@ impl Context {
|
|||||||
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
|
message::delete_msgs(self, &[MsgId::new(webxdc_message_id)]).await?;
|
||||||
}
|
}
|
||||||
self.sql.set_raw_config(key, value).await?;
|
self.sql.set_raw_config(key, value).await?;
|
||||||
self.debug_logging.store(0, atomic::Ordering::Release);
|
self.debug_logging.store(0, atomic::Ordering::Relaxed);
|
||||||
} else {
|
} else {
|
||||||
let data: &[u8] = include_bytes!("../assets/webxdc_logging.xdc");
|
let data: &[u8] = include_bytes!("../assets/webxdc_logging.xdc");
|
||||||
|
|
||||||
@@ -352,7 +352,7 @@ impl Context {
|
|||||||
.set_raw_config(key, Some(&msg_id.to_u32().to_string()))
|
.set_raw_config(key, Some(&msg_id.to_u32().to_string()))
|
||||||
.await?;
|
.await?;
|
||||||
self.debug_logging
|
self.debug_logging
|
||||||
.store(msg_id.to_u32(), atomic::Ordering::Release);
|
.store(msg_id.to_u32(), atomic::Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@@ -442,15 +442,22 @@ impl Context {
|
|||||||
typ: event.clone(),
|
typ: event.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
let context = self.clone();
|
// `task::spawn()` below is a bit slow, so make sure to only call it if
|
||||||
let debug_logging = context.debug_logging.load(atomic::Ordering::Acquire);
|
// debug logging is enabled; that's why we have the Context::debug_logging
|
||||||
|
// property. Using `spawn()` also has the disadvantage that the logs might
|
||||||
|
// get out of order.
|
||||||
|
// Both could be solved by using `task::block_on()` instead, but reportedly,
|
||||||
|
// this could lead to deadlocks. A better solution would be to make
|
||||||
|
// `emit_event()` async.
|
||||||
|
let debug_logging = self.debug_logging.load(atomic::Ordering::Relaxed);
|
||||||
if debug_logging > 0 {
|
if debug_logging > 0 {
|
||||||
let time = SystemTime::now()
|
let time = SystemTime::now()
|
||||||
.duration_since(SystemTime::UNIX_EPOCH)
|
.duration_since(SystemTime::UNIX_EPOCH)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.as_millis() as i64;
|
.as_millis() as i64;
|
||||||
|
|
||||||
async_std::task::block_on(async move {
|
let context = self.clone();
|
||||||
|
async_std::task::spawn(async move {
|
||||||
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
let webxdc_instance_id = MsgId::new(debug_logging as u32);
|
||||||
|
|
||||||
match context
|
match context
|
||||||
|
|||||||
@@ -1288,7 +1288,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> {
|
|||||||
.sql
|
.sql
|
||||||
.set_raw_config(Config::DebugLogging, Some("0"))
|
.set_raw_config(Config::DebugLogging, Some("0"))
|
||||||
.await?;
|
.await?;
|
||||||
context.debug_logging.store(0, atomic::Ordering::Release);
|
context.debug_logging.store(0, atomic::Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ impl Sql {
|
|||||||
let debug_logging = self.get_raw_config_u32(Config::DebugLogging).await?;
|
let debug_logging = self.get_raw_config_u32(Config::DebugLogging).await?;
|
||||||
context
|
context
|
||||||
.debug_logging
|
.debug_logging
|
||||||
.store(debug_logging.unwrap_or(0), atomic::Ordering::Release);
|
.store(debug_logging.unwrap_or(0), atomic::Ordering::Relaxed);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user