diff --git a/src/context.rs b/src/context.rs index 1babc592e..c0a4b8621 100644 --- a/src/context.rs +++ b/src/context.rs @@ -243,7 +243,10 @@ pub struct InnerContext { pub(crate) last_error: std::sync::RwLock, /// If debug logging is enabled, this contains all necessary information - pub(crate) debug_logging: RwLock>, + /// + /// Standard RwLock instead of [`tokio::sync::RwLock`] is used + /// because the lock is used from synchronous [`Context::emit_event`]. + pub(crate) debug_logging: std::sync::RwLock>, } /// The state of ongoing process. @@ -382,7 +385,7 @@ impl Context { creation_time: std::time::SystemTime::now(), last_full_folder_scan: Mutex::new(None), last_error: std::sync::RwLock::new("".to_string()), - debug_logging: RwLock::new(None), + debug_logging: std::sync::RwLock::new(None), }; let ctx = Context { @@ -438,7 +441,7 @@ impl Context { /// Emits a single event. pub fn emit_event(&self, event: EventType) { { - let lock = tokio::task::block_in_place(|| self.debug_logging.blocking_read()); + let lock = self.debug_logging.read().expect("RwLock is poisoned"); if let Some(debug_logging) = &*lock { debug_logging.log_event(event.clone()); } diff --git a/src/debug_logging.rs b/src/debug_logging.rs index 998b0ab76..7b343a35f 100644 --- a/src/debug_logging.rs +++ b/src/debug_logging.rs @@ -134,7 +134,7 @@ pub(crate) async fn set_debug_logging_xdc(ctx: &Context, id: Option) -> a ) .await?; { - let debug_logging = &mut *ctx.debug_logging.write().await; + let debug_logging = &mut *ctx.debug_logging.write().expect("RwLock is poisoned"); match debug_logging { // Switch logging xdc Some(debug_logging) => debug_logging.msg_id = msg_id, @@ -162,7 +162,7 @@ pub(crate) async fn set_debug_logging_xdc(ctx: &Context, id: Option) -> a ctx.sql .set_raw_config(Config::DebugLogging.as_ref(), None) .await?; - *ctx.debug_logging.write().await = None; + *ctx.debug_logging.write().expect("RwLock is poisoned") = None; info!(ctx, "removing logging webxdc"); } } diff --git a/src/message.rs b/src/message.rs index ea72a8c99..52642ed44 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1425,7 +1425,7 @@ pub async fn delete_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> { let logging_xdc_id = context .debug_logging .read() - .await + .expect("RwLock is poisoned") .as_ref() .map(|dl| dl.msg_id); diff --git a/src/scheduler.rs b/src/scheduler.rs index 840824f09..1c2bf861a 100644 --- a/src/scheduler.rs +++ b/src/scheduler.rs @@ -105,7 +105,12 @@ impl SchedulerState { // to allow for clean shutdown. context.new_msgs_notify.notify_one(); - if let Some(debug_logging) = context.debug_logging.read().await.as_ref() { + if let Some(debug_logging) = context + .debug_logging + .read() + .expect("RwLock is poisoned") + .as_ref() + { debug_logging.loop_handle.abort(); } let prev_state = std::mem::replace(&mut *inner, new_state); diff --git a/src/webxdc.rs b/src/webxdc.rs index cf143da12..2a8217667 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -2466,9 +2466,9 @@ sth_for_the = "future""# include_bytes!("../test-data/webxdc/minimal.xdc"), ) .await?; - assert!(alice.debug_logging.read().await.is_none()); + assert!(alice.debug_logging.read().unwrap().is_none()); send_msg(&alice, chat_id, &mut instance).await?; - assert!(alice.debug_logging.read().await.is_some()); + assert!(alice.debug_logging.read().unwrap().is_some()); alice.emit_event(EventType::Info("hi".to_string())); alice