From ff02aba40dd599373380631a1d0e87ecbed3f8b5 Mon Sep 17 00:00:00 2001 From: gennyble Date: Wed, 2 Apr 2025 12:36:48 -0500 Subject: mutex on modules so only one request can be handled at a time --- corgi/src/caller.rs | 15 +++++++++++++++ corgi/src/main.rs | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/corgi/src/caller.rs b/corgi/src/caller.rs index aef6bc3..7014d22 100644 --- a/corgi/src/caller.rs +++ b/corgi/src/caller.rs @@ -213,6 +213,20 @@ unsafe fn module_thread(script: Script, req: HttpRequest, tx: Sender If the same shared object is opened again with dlopen(), + // > the same object handle is returned. + let lock = match script.module_lock.lock() { + Ok(lock) => lock, + Err(poison) => { + eprintln!("!!! mutex for {} was poisoned!", script.name); + + // get the guard + poison.into_inner() + } + }; + unsafe { let lib = libloading::Library::new(script.filename).unwrap(); let handle: libloading::Symbol = lib.get(b"cgi_handle").unwrap(); @@ -240,5 +254,6 @@ unsafe fn module_thread(script: Script, req: HttpRequest, tx: Sender>, regex: Option, filename: String, env: Vec<(String, String)>, @@ -107,6 +108,7 @@ fn parse_script_conf(conf: &Value) -> Script { Script { name, kind, + module_lock: Arc::new(Mutex::new(())), regex, filename, env: env.unwrap_or_default(), -- cgit 1.4.1-3-g733a5