mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-13 20:26:52 +00:00
refactor(admin): Release handle lock before command execution
Change admin service handle to SyncRwLock and copy the handler function pointer before awaiting execution to prevent deadlock.
This commit is contained in:
3 files changed
+13
-15
No files matched your search
@@ -27,7 +27,6 @@ use ruma::{
|
||||
},
|
||||
},
|
||||
};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::{
|
||||
Dep, account_data, config, globals,
|
||||
@@ -38,7 +37,7 @@ use crate::{
|
||||
pub struct Service {
|
||||
services: Services,
|
||||
channel: (Sender<CommandInput>, Receiver<CommandInput>),
|
||||
pub handle: RwLock<Option<Processor>>,
|
||||
pub handle: SyncRwLock<Option<Processor>>,
|
||||
pub complete: SyncRwLock<Option<Completer>>,
|
||||
#[cfg(feature = "console")]
|
||||
pub console: Arc<console::Console>,
|
||||
@@ -131,7 +130,7 @@ impl crate::Service for Service {
|
||||
media: args.depend::<crate::media::Service>("media"),
|
||||
},
|
||||
channel: loole::bounded(COMMAND_QUEUE_LIMIT),
|
||||
handle: RwLock::new(None),
|
||||
handle: SyncRwLock::new(None),
|
||||
complete: SyncRwLock::new(None),
|
||||
#[cfg(feature = "console")]
|
||||
console: console::Console::new(&args),
|
||||
@@ -372,8 +371,11 @@ impl Service {
|
||||
}
|
||||
|
||||
async fn process_command(&self, command: CommandInput) -> ProcessorResult {
|
||||
let handle_guard = self.handle.read().await;
|
||||
let handle = handle_guard.as_ref().expect("Admin module is not loaded");
|
||||
let handle = *self
|
||||
.handle
|
||||
.read()
|
||||
.as_ref()
|
||||
.expect("Admin module is not loaded");
|
||||
|
||||
let services = self
|
||||
.services
|
||||
|
||||
Reference in new issue
Block a user