Skip to content

fix(nio-filesystem): Fallback to non-positional read/write on ENXIO (Fixes #3613) - #3671

Merged
glbrntt merged 3 commits into
apple:mainfrom
wasim-builds:fix/issue-3613-pwrite-terminal-enxio
Jul 22, 2026
Merged

glbrntt merged 3 commits into
apple:mainfrom
wasim-builds:fix/issue-3613-pwrite-terminal-enxio

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Hey @weissi! 👋

This PR addresses #3613 where writing to /dev/stdout fails with ENXIO (6) Device not configured when running in a terminal environment instead of a pipe.

Currently, SystemFileHandle checks for errno == .illegalSeek (ESPIPE) when deciding whether to fall back from positional pwrite/pread to non-positional write/read for unseekable files like pipes. However, macOS/Darwin returns ENXIO (Errno.noSuchDeviceOrAddress) instead of ESPIPE when attempting a positional write/read on a terminal device.

Changes:

  • Added .noSuchDeviceOrAddress to the fallback conditions in SystemFileHandle.swift for both readChunk and write.
  • Updated FileSystemError+Syscall.swift to map .noSuchDeviceOrAddress to .unsupported alongside .illegalSeek.
  • Replicated these changes across both the _NIOFileSystem and NIOFS modules.

This allows FileSystem.shared.withFileHandle and other APIs to work transparently with terminal devices like /dev/stdout!

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has lots of unrelated changes, can you trim it down to just the ones relevant to this PR?

@wasim-builds
wasim-builds force-pushed the fix/issue-3613-pwrite-terminal-enxio branch from cf804dc to 2d3c4a9 Compare July 22, 2026 09:58
@wasim-builds

Copy link
Copy Markdown
Contributor Author

Thanks @glbrntt! I've trimmed down the branch to contain only the single relevant commit for the ENXIO fallback fix.

from the file system.
"""
case .illegalSeek:
case .illegalSeek, .noSuchDeviceOrAddress:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are tests that validate these mappings. Can you update them please?

@wasim-builds

Copy link
Copy Markdown
Contributor Author

Thanks @glbrntt, I have just updated the FileSystemErrorTests to validate the new mappings for noSuchDeviceOrAddress!

@glbrntt glbrntt added the 🔨 semver/patch No public API change. label Jul 22, 2026

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@glbrntt glbrntt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile on Linux, you'll need to fix that up too.

@wasim-builds

Copy link
Copy Markdown
Contributor Author

Ah, good catch! I accidentally used noSuchDeviceOrAddress, which compiles on macOS but fails on Linux since the swift-system Errno property is officially named noSuchAddressOrDevice across all platforms. I've updated the property names everywhere to fix the Linux builds!

@glbrntt
glbrntt merged commit 3777a70 into apple:main Jul 22, 2026
53 of 57 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants