Skip to content

Commit

Permalink
Wasm-wc: Fix application restarts
Browse files Browse the repository at this point in the history
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(2)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(2).

So that's what we do.

We want to use the standard EXIT_SUCCESS mnemonic, which in rust is
available in external crates such as libc, however rather than bringing
in a whole nother crate just for this, we just define it locally
ourselves.

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>
Signed-off-by: Andrew Clayton <a.clayton@nginx.com>
  • Loading branch information
ac000 committed Mar 11, 2024
1 parent 4c03309 commit 3eddef8
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/wasm-wasi-component/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use anyhow::{bail, Context, Result};
use bytes::{Bytes, BytesMut};
use http_body_util::combinators::BoxBody;
use http_body_util::{BodyExt, Full};
use std::ffi::{CStr, CString};
use std::ffi::{c_int, CStr, CString};
use std::mem::MaybeUninit;
use std::process::exit;
use std::ptr;
use std::sync::OnceLock;
use tokio::sync::mpsc;
Expand Down Expand Up @@ -101,6 +102,8 @@ unsafe extern "C" fn start(
task: *mut bindings::nxt_task_t,
data: *mut bindings::nxt_process_data_t,
) -> bindings::nxt_int_t {
const EXIT_SUCCESS: c_int = 0;

handle_result(task, || {
let config = GLOBAL_CONFIG.get().unwrap();
let state = GlobalState::new(&config)
Expand All @@ -126,7 +129,7 @@ unsafe extern "C" fn start(
bindings::nxt_unit_run(unit_ctx);
bindings::nxt_unit_done(unit_ctx);

Ok(())
exit(EXIT_SUCCESS);
})
}

Expand Down

0 comments on commit 3eddef8

Please sign in to comment.