Skip to content

gh-145030: Fix asyncio write pipe transport for named FIFOs on macOS#154222

Merged
kumaraditya303 merged 4 commits into
python:mainfrom
bhuvi27:gh-145030-fix-fifo-write-transport-macos
Jul 24, 2026
Merged

gh-145030: Fix asyncio write pipe transport for named FIFOs on macOS#154222
kumaraditya303 merged 4 commits into
python:mainfrom
bhuvi27:gh-145030-fix-fifo-write-transport-macos

Conversation

@bhuvi27

@bhuvi27 bhuvi27 commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Fixes #145030

On macOS, the write end of a named FIFO polls as readable whenever unread data sits in the FIFO (the kernel does not check the fd's access mode,unlike Linux), so the "reader trick" _UnixWritePipeTransport uses to detect
the peer closing misfired and closed the transport, making the next drain() raise ConnectionResetError. The trick also cannot detect a genuine hangup for named FIFOs on macOS: closing the read end produces no event, and
kqueue's EV_EOF tracks writers rather than readers.

Skip registering the reader for named FIFOs on macOS, matching the existing AIX carve-out; a closed peer is still detected on the next write via EPIPE. Anonymous os.pipe() pipes are unaffected (st_nlink == 0) and keep the
current behaviour. Adds a regression test that keeps unread data in a FIFO while iterating the loop, which fails without the fix on macOS.

…macOS

On macOS the write end of a named FIFO polls as readable whenever
unread data sits in the FIFO, so the reader trick used to detect the
peer closing misfired and closed the transport. The trick also cannot
detect a genuine hangup there: closing the read end delivers no event
and kqueue's EV_EOF tracks writers, not readers. Skip registering the
reader for named FIFOs on macOS, like the existing AIX carve-out; a
closed peer is still detected on the next write via EPIPE. Anonymous
os.pipe() pipes (st_nlink == 0) keep the current behaviour.
bhuvi27 added 2 commits July 20, 2026 13:52
sys.platform is "ios" (etc.) on Apple mobile, not "darwin", so the
named-FIFO carve-out never applied there and the new regression test
failed on the iOS CI job. Match all Apple platforms.
Rename the carve-out variable and wording back to macOS; keep the
platform set covering ios/tvos/watchos so the same xnu FIFO behaviour
is handled there.
Comment thread Lib/test/test_asyncio/test_events.py
Comment thread Lib/asyncio/unix_events.py Outdated
Comment thread Lib/asyncio/unix_events.py
Rename is_named_fifo_on_macos to is_named_fifo_on_apple to match the
Apple platform set, and assert st_nlink != 0 in the named FIFO test.
@bhuvi27
bhuvi27 requested a review from kumaraditya303 July 24, 2026 12:33
@kumaraditya303
kumaraditya303 merged commit 409f324 into python:main Jul 24, 2026
54 checks passed
@kumaraditya303 kumaraditya303 added topic-asyncio awaiting merge needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 24, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @bhuvi27 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @bhuvi27 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @bhuvi27 for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154611 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jul 24, 2026
@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154612 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jul 24, 2026
@bedevere-app

bedevere-app Bot commented Jul 24, 2026

Copy link
Copy Markdown

GH-154613 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 24, 2026
kumaraditya303 pushed a commit that referenced this pull request Jul 24, 2026
… macOS (GH-154222) (#154611)

gh-145030: Fix asyncio write pipe transport for named FIFOs on macOS (GH-154222)
(cherry picked from commit 409f324)

Co-authored-by: Bhuvi <b.chouksey27@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.streams.streamWriter used with a fifo on macOS closes after one write

2 participants