Skip to content

comm: share standard input between both operands - #14376

Open
harshasiddartha wants to merge 1 commit into
uutils:mainfrom
harshasiddartha:comm-stdin-both-operands
Open

comm: share standard input between both operands#14376
harshasiddartha wants to merge 1 commit into
uutils:mainfrom
harshasiddartha:comm-stdin-both-operands

Conversation

@harshasiddartha

Copy link
Copy Markdown
Contributor

printf 'test' | comm - - hangs forever without printing anything.

Each operand is opened on its own, and - becomes stdin().lock(). That lock is not reentrant, so the second - blocks on it before any input is read.

Both operands now share one lock, taking lines from the single stream in turn. That is what GNU comm prints too: for a\nb\nc\n on standard input, GNU and this branch both write a, \tb, c. GNU also reports comm: -: Bad file descriptor and exits 1, which comes from it closing standard input twice; that is not reproduced here, and the exit status is 0 as with BSD comm.

One difference I did not chase: with --total, GNU prints no totals line, because it dies in the double close before reaching it, while this branch prints the counts. That follows from the same double-close artifact described above.

Tested with a new case in tests/by-util/test_comm.rs that pipes a\nb\nc\n into comm - - and checks the output. It has an explicit timeout, so it fails instead of hanging if the deadlock ever comes back; it does fail on that timeout without this change.

Fixes #14219

`comm - -` locked standard input once per operand and deadlocked on the
second lock, before reading anything. Hand both operands the same lock
instead, so they take lines from the one stream in turn, which is what
GNU comm prints for the same input.
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.

@oech3

oech3 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

I don't want to have stdin specific code just for 1 undefined behaviour.
Note that this is actually applied for all 2 same streams e.g. a shared named fifo.

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.

comm: "- -" deadlocks

2 participants