Skip to content

WIP: fix(executor): bind winning /dev/tcp input redirects for in-process commands (rubash#2124) - #2139

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/2124-builtin-net-input
Oct 29, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/2124-builtin-net-input

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

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 spurious No such file or directory; mapfile fell 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_redirections performs 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)

  • 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 (fd ≥ 3) net Input entry — connect exactly once via open_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.
  • read coordination: a dispatch_net_bound_fds scratch set lets read serve the bound fd-0 endpoint instead of connecting a second time.
  • 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-fd 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.

Verification

Full evidence: cluster REPORT.md (kept in the workspace, not in this PR).

caomengxuan666 and others added 2 commits October 29, 2026 15:50
…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]>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 17:08
@caomengxuan666
caomengxuan666 merged commit aeaae92 into master Oct 29, 2026
10 of 11 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/2124-builtin-net-input 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] 内建命令的 /dev/tcp 胜出输入重定向在 Linux 上从不连接且静默无诊断

1 participant