Skip to content

tee: fix hang on broken stdout pipe in -p mode and add regression test#10599

Closed
Paol0B wants to merge 8 commits intouutils:mainfrom
Paol0B:fix/10308-tee--p-(Linux)-ensure_stdout_not_broken-Can-Hang-Forever-on-Pipes
Closed

tee: fix hang on broken stdout pipe in -p mode and add regression test#10599
Paol0B wants to merge 8 commits intouutils:mainfrom
Paol0B:fix/10308-tee--p-(Linux)-ensure_stdout_not_broken-Can-Hang-Forever-on-Pipes

Conversation

@Paol0B
Copy link
Copy Markdown
Contributor

@Paol0B Paol0B commented Jan 30, 2026

close #10308

Fix: tee -p (Linux) ensure_stdout_not_broken Can Hang Forever on Pipes

Problem
tee -p hangs indefinitely in normal pipelines (e.g., echo "test" | tee -p file | cat) on Linux.

Root Cause
ensure_stdout_not_broken() used POLLRDBAND which doesn't work with standard Unix pipes, causing improper pipe state detection.

Solution
Changed poll flag from POLLRDBAND to POLLOUT:

Correctly detects broken pipes via POLLERR (automatically checked by poll)
Uses zero timeout (non-blocking)
Properly handles both healthy and broken pipes

Changes
signals.rs: Updated ensure_stdout_not_broken() to use POLLOUT
tee.rs: Restored pre-check with better documentation
test_tee.rs: Added regression test test_pipe_mode_normal_pipeline_no_hang

Comment thread tests/by-util/test_tee.rs Outdated
Comment thread tests/by-util/test_tee.rs
Comment thread tests/by-util/test_tee.rs Outdated
@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/shuf/shuf-reservoir (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/sort/sort-stale-thread-mem (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)

@Paol0B Paol0B requested a review from ChrisDryden February 5, 2026 19:11
@ChrisDryden
Copy link
Copy Markdown
Collaborator

Changes look great just have some linting issues

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 9, 2026

GNU testsuite comparison:

Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/tail/tail-n0f is now passing!

@github-actions
Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/pr/bounded-memory. tests/pr/bounded-memory is passing on 'main'. Maybe you have to rebase?

@ChrisDryden
Copy link
Copy Markdown
Collaborator

Is it possible that this was fixed with the pipeline signal handling? I am having trouble replicating the original issue now

@ChrisDryden
Copy link
Copy Markdown
Collaborator

I did some digging into the git history to see if I could see if the bug existed and then was already fixed and I was able to replicate it before: #9585 I believe that PR already fixed the issue

@ChrisDryden
Copy link
Copy Markdown
Collaborator

Sorry about the extra work here, I should have validated the use case before I started reviewing this

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.

tee -p (Linux) ensure_stdout_not_broken Can Hang Forever on Pipes

3 participants