Skip to content

Commit

Permalink
Merge pull request #4293 from wasmerio/fix-for-closing-fds
Browse files Browse the repository at this point in the history
When the main thread was exiting it was not flushing and properly closing file descriptors
  • Loading branch information
syrusakbary authored Nov 6, 2023
2 parents d18aa79 + 639ad10 commit a60676d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/wasix/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>()
Expand All @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit a60676d

Please sign in to comment.