diff --git a/lib/wasix/src/fs/mod.rs b/lib/wasix/src/fs/mod.rs index be813fea339..a1fe86e05d0 100644 --- a/lib/wasix/src/fs/mod.rs +++ b/lib/wasix/src/fs/mod.rs @@ -566,6 +566,17 @@ impl WasiFs { } } + /// We need to clear the freed FD list when the journal is replayed as it + /// will close lots of file descriptors which will fill the list. We clear + /// the list and allocate new FD's instead. + /// + /// This should only be used when the file descriptors are being managed + /// externally (e.g. journals) + pub(crate) fn clear_freed_fd_list(&self) { + let mut freed_fds = self.freed_fds.write().unwrap(); + freed_fds.clear(); + } + /// Closes all the file handles. #[allow(clippy::await_holding_lock)] pub async fn close_all(&self) { diff --git a/lib/wasix/src/syscalls/journal/restore_snapshot.rs b/lib/wasix/src/syscalls/journal/restore_snapshot.rs index 883bd1d1812..2f2699194bc 100644 --- a/lib/wasix/src/syscalls/journal/restore_snapshot.rs +++ b/lib/wasix/src/syscalls/journal/restore_snapshot.rs @@ -62,6 +62,10 @@ pub unsafe fn restore_snapshot( .map_err(anyhow_err_to_runtime_err)?; } + // Reset the freed FD's so that none of them will be reused after + // the journal resumes + runner.ctx.data().state().fs.clear_freed_fd_list(); + // Once we get to this point we are no longer replaying the journal // and need to clear this flag, the reason is that restoring the // background threads may immediately process requests while this