Problem
The append_file method in src/interpreter/mod.rs currently holds the global file_handles mutex while performing async I/O operations (seek/write/flush/sync). This blocks all other file operations unnecessarily during the I/O.
Current Implementation
The method performs all I/O operations while holding the lock:
let (_, file) = match file_handles.get_mut(handle_id) {
Some(entry) => entry,
None => return Err(format\!("Invalid file handle: {handle_id}")),
};
match AsyncSeekExt::seek(file, std::io::SeekFrom::End(0)).await {
// ... all I/O operations while holding the lock
}
Proposed Solution
Clone the file handle while holding the lock, then drop the lock before performing I/O:
- Get mutable reference to file and clone it while lock is held
- Drop the lock immediately after cloning
- Perform all async I/O operations on the cloned handle
This pattern should also be applied to other methods like write_file and close_file that have similar issues.
References
Files to Modify
src/interpreter/mod.rs - append_file, write_file, close_file methods
Problem
The
append_filemethod insrc/interpreter/mod.rscurrently holds the globalfile_handlesmutex while performing async I/O operations (seek/write/flush/sync). This blocks all other file operations unnecessarily during the I/O.Current Implementation
The method performs all I/O operations while holding the lock:
Proposed Solution
Clone the file handle while holding the lock, then drop the lock before performing I/O:
This pattern should also be applied to other methods like
write_fileandclose_filethat have similar issues.References
Files to Modify
src/interpreter/mod.rs-append_file,write_file,close_filemethods