Skip to content

fix(executor): mapfile reads coproc fds via the string channel (rubash#1659) - #1696

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix-1659-mapfile-coproc-fd
Oct 26, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix-1659-mapfile-coproc-fd

Conversation

@arookieofc

Copy link
Copy Markdown
Member

Fixes #1659.

GNU mapfile.def reads its input descriptor to EOF, so mapfile -t arr <&${COPROC[0]} must block-read the coproc pipe. Rubash's mapfile dispatch only applies output redirects (apply_no_output_builtin_redirects), so its input comes from the string channels (stdin_string_for_command), and that channel's open_fd_read_endpoint had no arm for the coproc pipe read end (FdReadEndpoint::CoprocStdout) — every sibling reader (read_all_bytes, take_buffered_input_line, inherited_async_stdin) already served it, but this helper dropped it to Bad file descriptor. The string channel then failed and mapfile fell through to reading inherited process stdin: a hang on a held-open pipe, or 0 lines on /dev/null (both manifestations trace to the same hole).

The fix serves CoprocStdout in open_fd_read_endpoint exactly like a file: DuplicateHandle shares the kernel object, so a preceding read and a following mapfile see GNU's shared-offset stream (read takes a, mapfile gets b c), not a replay.

Verification (local, master 499a5e2 + this fix, vs GNU bash 5.3.20): <& coproc fd, -u coproc fd, read-then-mapfile shared offset, slow coproc (sleep 1 then output), and plain file/heredoc/herestring/pipe/delimiter mapfile sources all match GNU; cat <&${COPROC[0]} control still works.

Regression tests: tests/issue1659_mapfile_coproc_fd_regressions.rs, 5/5 passed; existing mapfile suites (issue1207, issue1297, issue1420, issue324, issue680 x2) still pass.

…h#1659)

GNU mapfile.def reads its input descriptor to EOF, so
'mapfile -t arr <&${COPROC[0]}' must block-read the
coproc pipe. Rubash's mapfile dispatch only applies
output redirects (apply_no_output_builtin_redirects), so
its input comes from the string channels
(stdin_string_for_command), and that channel's
open_fd_read_endpoint had no arm for the coproc pipe
read end (FdReadEndpoint::CoprocStdout) — every sibling
reader (read_all_bytes, take_buffered_input_line,
inherited_async_stdin) already served it, but this
helper dropped it to Bad file descriptor. The string
channel then failed and mapfile fell through to reading
inherited process stdin: a hang on a held-open pipe,
or 0 lines on /dev/null.

The fix serves CoprocStdout in open_fd_read_endpoint
exactly like a file: DuplicateHandle shares the kernel
object, so a preceding 'read' and a following mapfile
see GNU's shared-offset stream (read takes a, mapfile
gets b c), not a replay.

Regression tests:
tests/issue1659_mapfile_coproc_fd_regressions.rs (5 tests:
<& coproc fd, -u coproc fd, shared offset after read,
slow coproc, plain file/heredoc sources unchanged).
@caomengxuan666
caomengxuan666 merged commit 6d72d5f into master Oct 26, 2026
7 of 10 checks passed
@caomengxuan666
caomengxuan666 deleted the fix-1659-mapfile-coproc-fd branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] mapfile from coproc fd returns instantly with 0 lines (GNU blocks and reads); read/cat on same fd work

2 participants