Skip to content
This repository was archived by the owner on Oct 8, 2025. It is now read-only.

Commit e75f8d5

Browse files
committed
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: 20ada4b ("Wasm-wc: Core of initial Wasm component model language module support") Closes: #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>
1 parent a8cfea8 commit e75f8d5

File tree

1 file changed

+12
-3
lines changed
  • src/wasm-wasi-component/src

1 file changed

+12
-3
lines changed

src/wasm-wasi-component/src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use http_body_util::combinators::BoxBody;
44
use http_body_util::{BodyExt, Full};
55
use std::ffi::{CStr, CString};
66
use std::mem::MaybeUninit;
7+
use std::process::exit;
78
use std::ptr;
89
use std::sync::OnceLock;
910
use tokio::sync::mpsc;
@@ -101,7 +102,9 @@ unsafe extern "C" fn start(
101102
task: *mut bindings::nxt_task_t,
102103
data: *mut bindings::nxt_process_data_t,
103104
) -> bindings::nxt_int_t {
104-
handle_result(task, || {
105+
let mut rc: i32 = 0;
106+
107+
let result = handle_result(task, || {
105108
let config = GLOBAL_CONFIG.get().unwrap();
106109
let state = GlobalState::new(&config)
107110
.context("failed to create initial state")?;
@@ -123,11 +126,17 @@ unsafe extern "C" fn start(
123126
bail!("nxt_unit_init() failed");
124127
}
125128

126-
bindings::nxt_unit_run(unit_ctx);
129+
rc = bindings::nxt_unit_run(unit_ctx);
127130
bindings::nxt_unit_done(unit_ctx);
128131

129132
Ok(())
130-
})
133+
});
134+
135+
if result != bindings::NXT_OK as bindings::nxt_int_t {
136+
return result;
137+
}
138+
139+
exit(rc);
131140
}
132141

133142
unsafe fn handle_result(

0 commit comments

Comments
 (0)