Repository navigation
fix(executor): mapfile reads coproc fds via the string channel (rubash#1659) - #1696
Merged
Merged
Conversation
…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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
readand 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.