Skip to content

fix(executor): route pipeline stage stderr through the fd table in command substitution - #3364

Merged
caomengxuan666 merged 2 commits into
unixwin:masterfrom
Uarz:fix/issue-3308
Nov 11, 2026
Merged

caomengxuan666 merged 2 commits into
unixwin:masterfrom
Uarz:fix/issue-3308

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #3308

What was fixed

In script mode, $(external | external) let the first pipeline stage's stderr bypass every redirect and write straight to the console (-c mode was fine). A pipeline stage's fd 2 must be resolved from the executor's fd table, never from the process's raw stderr.

The fix adds a ConcurrentPipelineStderr plan (Inherit / Null / Direct / Piped) to the Unix concurrent twin paths, resolving each stage's fd 2 from the fd table and re-emitting collected stage stderr through write_default_stderr. The prefix-streaming-tail path, which never set stderr on spawn at all, gets the same plan plus per-member drain threads and ordered re-emission after reap. The sequential path's pipeline_stage_stdio_targets no longer misreads "no output redirect" as unparseable.

What was deleted

Nothing. No files, features, or tests were removed. (A temporary DBG3308 debug print added during the work was deleted before this PR.)

Verification (all run, per-item counts)

  • Regression pin tests/issue3308_comsub_pipeline_stderr_redirects.rs: 18/18 pass. Fail-first on the unpatched tree: 3 passed / 13 failed (16 pre-existing cases; the 2 prefix-streaming-tail cases were evidenced by a probe leak on the unpatched tree).
  • issue1552_ambient_stderr_pipeline_diagnostic_regressions: 8/8 pass.
  • Adjacent files: 35 passed / 0 failed / 1 ignored across 10 neighbouring test files.
  • GNU 5.3.20 probe matrix: 12/13 match (the one mismatch is concurrent-write line ordering, which is nondeterministic in GNU itself across runs; the pin asserts on sets).
  • cargo build -j 2 --bin rubash clean, cargo fmt --check clean. src/lexer/continuation.rs untouched.

Owed

  1. Windows twin paths carry the same mechanism bug and are unverified on this Linux VM.
  2. d2 sequential-loop residual: { echo hi | ls /bad; } 2>&1 1>out.txt — GNU puts the error on stdout; rubash's sequential loop puts it in out.txt. Addressing it means reworking the [bug] 计时管道以 dash 词作首段时丢失 command not found 诊断 #1552 merge semantics; left out of scope.
  3. /dev/tcp output face: plain > opens the connection twice and delivers zero bytes with a write error (output-side sibling of #1950) #1967 counting-server flake is pre-existing (fails on the unpatched tree too).

…mmand substitution

In script mode the first stage of a pipeline inside $(...) wrote its stderr straight to the process console, bypassing all redirects. Pipeline stage fd 2 must be resolved from the executor fd table, and collected stage stderr re-emitted through the fd-2 face, never through raw process stderr.

Refs unixwin#3308

Regression pin: tests/issue3308_comsub_pipeline_stderr_redirects.rs (18 tests; fail-first 13 failed on the unpatched tree, 18/18 pass after). issue1552 ambient-stderr family 8/8 green. GNU 5.3.20 probe matrix 12/13 match (one concurrent-write ordering case is nondeterministic in GNU itself).

Owed: Windows twin paths carry the same mechanism bug and are unverified on this Linux VM; d2 sequential-loop residual (2>&1 snapshot not honoured when fd 1 is rebound); unixwin#1967 counting-server flake is pre-existing.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复 area:fd redirection, fd table, /dev/* emulation, dup/close ordering labels Nov 11, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 11, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR. This is queued for captain review — collaborator PRs are reviewed by the captain before merge, and #3308 stays open until that review lands. CI at intake: all checks green. No action needed unless the review asks for changes.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 11, 2026 17:19
@caomengxuan666
caomengxuan666 merged commit a0c4644 into unixwin:master Nov 11, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:fd redirection, fd table, /dev/* emulation, dup/close ordering bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P2-medium 中:次要缺陷或边缘路径,排期修复

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug][fd] 脚本模式 $(外部 | 外部):管道首进程 stderr 绕过全部重定向直写控制台(-c 模式正常;GNU 无此行为)

2 participants