Repository navigation
WIP: fix(executor): bind winning /dev/tcp input redirects for in-process commands (rubash#2124) - #2139
Merged
Conversation
…ommands (rubash#2124) GNU redir.c do_redirections performs the open of every redirection before the body runs, for every command class — for a /dev/tcp|udp target the open IS the connect (redir_open -> netopen). rubash's in-process funnels only probed the winner (the #1950 validate-by-resolution rule: a probe must not connect, the bind performs the one open) but had no bind, so a builtin's winning net input never connected: no connection, no data, and a refused connect silently rc 0. Compounds and function calls classified the target by filesystem metadata and reported a spurious ENOENT (or, for mapfile, fell back to the ambient stdin and hung). One category rule at the shared layers, no per-builtin cases: - Simple-command funnel (execute_materialized_command): for in-process routes (builtin/function names, exec and jobspecs excluded), bind the fd-0 winner and every surviving numbered net Input entry — connect exactly once via open_net_redirect, restore after dispatch. ReadWrite survivors bind the one socket on both endpoints (r_input_output). A failed connect renders the GNU diagnostic through the command's fd-2 routing, sets status 1, and skips the dispatch. - read serve: a dispatch_net_bound_fds scratch set lets read consume the bound fd-0 endpoint instead of connecting again. - Compounds: bind_command_fd0_input gains a net arm; compound_stdin_open_failure exempts net targets (the bind owns the outcome); the inner wrapper converts the bind's net io error into the open-failure shape (diagnostic, status 1, body skipped). The numbered ladder gains a net arm. - Function calls: function_call_stdin gains a net arm binding fd 0 for the body's duration. - Pipeline stages: a builtin stage carrying a net input redirect routes to the stage-subshell executor (where the funnel bind applies) instead of the inline slot arms, which apply no redirections at all. Co-Authored-By: Muse Spark <[email protected]>
Counting-listener harness (port 0, modeled on the #2098 suite; positive counts poll with a deadline): builtin winner connects once (echo/printf), reading builtins connect once and read the greeting (read/mapfile), function + brace-group + loop + subshell winners, numbered 3< winner, pipeline builtin stage, loser+winner one connect each, refused winner fails before the body with the two-line diagnostic, <> winners (echo/brace/3<>) connect once, external winner still exactly once (no double-connect vs #2098). Verified red on pristine master (6 of 8 fail; the external control and the loser+winner read shape are no-regression pins) and green on the fix. Co-Authored-By: Muse Spark <[email protected]>
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.
WIP: fix for the winning /dev/tcp input redirect never connecting on in-process commands.
Fixes #2124
Refs #2088
Defect
On the Linux build, a builtin command's WINNING /dev/tcp input redirect never connected and never errored — silent no-op (
echo hi < /dev/tcp/127.0.0.1/<port>connected 0 times; GNU connects once). A refused winner also ran the body with rc 0. Function calls and compounds reported a spuriousNo such file or directory;mapfilefell back to the ambient stdin and hung.Root cause: the in-process funnels only PROBE the winner (the #1950 validate-by-resolution rule — a probe must not connect, the bind performs the one open), but no in-process bind existed. Every working face (external spawn setup, exec, comsub, read's fd-0 serve) routes through the consume ladder that connects; the broken faces materialized the target through filesystem-shaped paths. GNU spec:
redir.c do_redirectionsperforms the open of every redirection before the body runs for every command class; for /dev/tcp|udp the open IS the connect (redir_open→netopen).Fix (one category rule at the shared layers, no per-builtin cases)
execute_materialized_command): for in-process routes (builtin/function names;execand jobspecs excluded), bind the fd-0 winner and every surviving numbered (fd ≥ 3) net Input entry — connect exactly once viaopen_net_redirect, restore after dispatch (undo_redirections). ReadWrite (<>) survivors bind the one socket on both endpoints (r_input_output). A failed connect renders the GNU diagnostic through the command's fd-2 routing, sets status 1, skips the dispatch.dispatch_net_bound_fdsscratch set letsreadserve the bound fd-0 endpoint instead of connecting a second time.bind_command_fd0_inputgains a net arm;compound_stdin_open_failureexempts net targets (the bind owns the outcome); the inner wrapper converts the bind's net io error into the open-failure shape (diagnostic + status 1 + body skipped). The numbered-fd ladder gains a net arm.function_call_stdingains a net arm binding fd 0 for the body's duration.Verification
-cand script-file modes.tests/issue2124_devtcp_winner_bind_regressions.rs(8 tests): red on pristine master (6 of 8; the other two are no-regression controls), green on the fix (3 consecutive runs).ownership_unary_operators_check_existing_fileplusunix_file_unary_operators_check_file_types_and_mode_bits, pre-existing in this environment);tests/regression.rs215/5/1 with the same five pre-existing failures on both trees (issue_1584, issue_1900, issue_759, issue_1887, issue_1888); fd suites 14/2 on both trees — the 2 failures are the /dev/tcp output face: plain > opens the connection twice and delivers zero bytes with a write error (output-side sibling of #1950) #1967 OUTPUT-side pins (> /dev/tcpwinner faces), failing identically on pristine master and belonging to the output-side family ([bug] 输出侧落选 net 重定向不 open + 管线合并形双连(#1950 家族输出面) #2121 territory), not this input fix.open_net_redirectprimitive the working Windows faces already use (the [bug] /dev/tcp 对端已关闭时写错误报 EINVAL(GNU 为 EPIPE 语义) #2102 socket-File caveat concerns write faces, not this input bind); the Windows goldens job is the adjudication surface.Full evidence: cluster REPORT.md (kept in the workspace, not in this PR).