From 639ad107965d818a95d06b11c783272d63b75753 Mon Sep 17 00:00:00 2001 From: Johnathan Sharratt Date: Sun, 5 Nov 2023 19:29:02 +1100 Subject: [PATCH] When the main thread was exiting it was not flushing and properly closing file descriptors --- lib/wasix/src/fs/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/wasix/src/fs/mod.rs b/lib/wasix/src/fs/mod.rs index 671bcfd65b7..163d9fc2b8c 100644 --- a/lib/wasix/src/fs/mod.rs +++ b/lib/wasix/src/fs/mod.rs @@ -462,10 +462,6 @@ impl WasiFs { pub async fn close_all(&self) { // TODO: this should close all uniquely owned files instead of just flushing. - if let Ok(mut map) = self.fd_map.write() { - map.clear(); - } - let to_close = { if let Ok(map) = self.fd_map.read() { map.keys().copied().collect::>() @@ -475,7 +471,7 @@ impl WasiFs { }; let _ = tokio::join!( - // Make sure the STDOUT and STDERR are explicitely flushed + // Make sure the STDOUT and STDERR are explicitly flushed self.flush(__WASI_STDOUT_FILENO), self.flush(__WASI_STDERR_FILENO), async { @@ -485,6 +481,10 @@ impl WasiFs { } } ); + + if let Ok(mut map) = self.fd_map.write() { + map.clear(); + } } /// Will conditionally union the binary file system with this one