diff options
author | Andrew Clayton <a.clayton@nginx.com> | 2024-03-07 16:16:55 +0000 |
---|---|---|
committer | Andrei Zeliankou <zelenkov@nginx.com> | 2024-03-15 15:12:59 +0000 |
commit | 777b7c87827f629a0df00c75d5bd1685c7ce1c35 (patch) | |
tree | 93133a2e1a6d713a2ec5d6e43cea6f39b25df27e | |
parent | d7ff6bb4a10e3999f788a2492944c70822441366 (diff) | |
download | unit-777b7c87827f629a0df00c75d5bd1685c7ce1c35.tar.gz unit-777b7c87827f629a0df00c75d5bd1685c7ce1c35.tar.bz2 |
Wasm-wc: Fix application restarts
Liam reported a problem when trying to restart wasm-wasi-component based
applications using the /control/applications/APPLICATION_NAME/restart
endpoint.
The application would become unresponsive.
What was happening was the old application process(es) weren't
exit(3)ing and so while we were starting new application processes, the
old ones were still hanging around in a non-functioning state.
When we are terminating an application it must call exit(3).
So that's what we do. We use the return value of nxt_unit_run() as the
exit status.
Due to exit(3)ing we also need to now explicitly handle the return on
error case.
Reported-by: Liam Crilly <liam@nginx.com>
Fixes: 20ada4b5c ("Wasm-wc: Core of initial Wasm component model language module support")
Closes: https://github.com/nginx/unit/issues/1179
Tested-by: Liam Crilly <liam@nginx.com>
Tested-by: Danielle De Leo <d.deleo@f5.com>
Co-developed-by: Dan Callahan <d.callahan@f5.com>
Signed-off-by: Dan Callahan <d.callahan@f5.com>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r-- | src/wasm-wasi-component/src/lib.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/wasm-wasi-component/src/lib.rs b/src/wasm-wasi-component/src/lib.rs index 3ee40c4f..b0552e81 100644 --- a/src/wasm-wasi-component/src/lib.rs +++ b/src/wasm-wasi-component/src/lib.rs @@ -4,6 +4,7 @@ use http_body_util::combinators::BoxBody; use http_body_util::{BodyExt, Full}; use std::ffi::{CStr, CString}; use std::mem::MaybeUninit; +use std::process::exit; use std::ptr; use std::sync::OnceLock; use tokio::sync::mpsc; @@ -101,7 +102,9 @@ unsafe extern "C" fn start( task: *mut bindings::nxt_task_t, data: *mut bindings::nxt_process_data_t, ) -> bindings::nxt_int_t { - handle_result(task, || { + let mut rc: i32 = 0; + + let result = handle_result(task, || { let config = GLOBAL_CONFIG.get().unwrap(); let state = GlobalState::new(&config) .context("failed to create initial state")?; @@ -123,11 +126,17 @@ unsafe extern "C" fn start( bail!("nxt_unit_init() failed"); } - bindings::nxt_unit_run(unit_ctx); + rc = bindings::nxt_unit_run(unit_ctx); bindings::nxt_unit_done(unit_ctx); Ok(()) - }) + }); + + if result != bindings::NXT_OK as bindings::nxt_int_t { + return result; + } + + exit(rc); } unsafe fn handle_result( |