Skip to content

Fix file_handles mutex contention in IoClient::close_file method #167

Description

@coderabbitai

Problem

The close_file method in src/interpreter/mod.rs currently holds the file_handles mutex while awaiting flush() and sync_all() operations, which serializes all I/O through this mutex and causes contention.

Current Code Location

  • File: src/interpreter/mod.rs
  • Lines: Around 416-429
  • Method: IoClient::close_file

Issue Details

  1. The mutex guard is held while awaiting async file operations
  2. This prevents concurrent access to file_handles by other tasks
  3. flush() on tokio::fs::File is effectively a no-op
  4. Should prefer sync_all() for durability and propagate errors properly

Proposed Solution

  • Remove the file handle from the HashMap while holding the lock
  • Drop the mutex guard immediately after removal
  • Perform async sync operations outside the mutex scope
  • Use sync_all() with fallback to sync_data() for proper error handling

References

Priority

This affects I/O performance and concurrency under load, particularly when multiple file operations are happening simultaneously.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions