From 199db321d847148b10df77cfea411919cba5b27a Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Sun, 5 Nov 2023 22:22:49 +1100 Subject: [PATCH] Terminate after flushing file descriptors --- lib/wasix/src/state/env.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/wasix/src/state/env.rs b/lib/wasix/src/state/env.rs index 36a5302b347..94aa03f4f15 100644 --- a/lib/wasix/src/state/env.rs +++ b/lib/wasix/src/state/env.rs @@ -1044,12 +1044,7 @@ impl WasiEnv { if self.thread.is_main() { tracing::trace!(pid=%self.pid(), "cleaning up open file handles"); - // Now send a signal that the thread is terminated - self.process.signal_process(Signal::Sigquit); - - // Terminate the process - let exit_code = exit_code.unwrap_or_else(|| Errno::Canceled.into()); - self.process.terminate(exit_code); + let process = self.process.clone(); let timeout = self.tasks().sleep_now(CLEANUP_TIMEOUT); let state = self.state.clone(); @@ -1063,6 +1058,13 @@ impl WasiEnv { }, _ = state.fs.close_all() => { } } + + // Now send a signal that the thread is terminated + process.signal_process(Signal::Sigquit); + + // Terminate the process + let exit_code = exit_code.unwrap_or_else(|| Errno::Canceled.into()); + process.terminate(exit_code); }) } else { Box::pin(async {})