Skip to content

🐛 fix(unix): suppress EIO on close in Docker bind mounts#513

Merged
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:512
Mar 11, 2026
Merged

🐛 fix(unix): suppress EIO on close in Docker bind mounts#513
gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat:512

Conversation

@gaborbernat
Copy link
Copy Markdown
Member

Since 3.20.4, releasing a UnixFileLock inside Docker on macOS with bind-mounted filesystems raises OSError: [Errno 5] Input/output error on os.close(fd). 🐛 The root cause is the unlink → flock unlock → close sequence in _release(): some FUSE-backed bind-mount drivers return EIO when closing an fd whose directory entry was already removed.

The unlink must stay before unlock to prevent a race where a concurrent acquirer locks the old inode while a new file is created, so reordering is not an option. Instead, os.close(fd) is now wrapped in suppress(OSError), matching the existing treatment of unlink. At that point the lock is already released and POSIX guarantees the fd is invalidated regardless of the close return value, so suppressing the error is safe.

Fixes #512

On macOS Docker with bind-mounted filesystems, the unlink-before-close
sequence in _release() causes os.close(fd) to raise EIO. The unlink must
stay before unlock to prevent a race where two processes lock different
inodes, so we suppress OSError on close instead. At that point the lock
is already released and POSIX guarantees the fd is invalidated regardless
of the close return value.

Fixes tox-dev#512
@gaborbernat gaborbernat enabled auto-merge (squash) March 11, 2026 20:38
@gaborbernat gaborbernat merged commit 42b740a into tox-dev:main Mar 11, 2026
32 checks passed
@gaborbernat gaborbernat deleted the 512 branch March 11, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnixFileLock._release raises OSError: [Errno 5] Input/output error in Docker bind-mounted setup (between 3.20.3 and 3.20.4)

1 participant