Skip to content

log: do not set O_NONBLOCK on stderr - #72818

Merged
SrinivasaBharath merged 1 commit into
ceph:mainfrom
tchaikov:wip-log-stderr-blocking
Nov 21, 2026
Merged

SrinivasaBharath merged 1 commit into
ceph:mainfrom
tchaikov:wip-log-stderr-blocking

Conversation

@tchaikov

@tchaikov tchaikov commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

2551130 fixed torn log lines on FIFO stderr by writing each line with a single write(2) per PIPE_BUF chunk, and also set O_NONBLOCK on stderr. The flag isn't needed for that: writes of up to PIPE_BUF bytes to a pipe are atomic in blocking mode too, see pipe(7).

And it does harm. The flag lives on the open file description, so when stdout shares the pipe, as with "2>&1 | less" or subprocess with stderr=STDOUT, stdout turns non-blocking too, even after we exit. If the reader falls behind, cout gets EAGAIN and drops the rest of the output while the tool still exits 0. That's how crushtool's output in set-choose.t gets cut off on busy make check nodes.

So keep the single-write path, but leave the flags alone. The EAGAIN handling stays in case someone else made the pipe non-blocking.

Fixes: https://tracker.ceph.com/issues/66997
Signed-off-by: Kefu Chai [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov

Copy link
Copy Markdown
Contributor Author

@batrick hey Patrick, do you mind reviewing this change?

Comment thread src/log/Log.cc
*
* This isn't required on Windows.
*/
stderr_is_fifo = S_ISFIFO(info.st_mode);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what I had missed was:

Write requests of {PIPE_BUF} bytes or less shall not be interleaved with data from other threads performing write operations on the same pipe or FIFO. Writes of greater than {PIPE_BUF} bytes may have data interleaved, on arbitrary boundaries, with write operations by other threads, whether or not the O_NONBLOCK flag of the file status flags is set.

from https://pubs.opengroup.org/onlinepubs/9799919799/functions/write.html#tag_17_699

(I prefer not to cite the Linux man pages for POSIX behavior.)

Comment thread src/log/Log.cc Outdated
/* Writes of at most PIPE_BUF bytes to a FIFO are atomic, so
* Log::_log_stderr() writes in such chunks to keep e.g. buggy container
* runtimes from reading torn log lines, as long as a line fits in
* PIPE_BUF bytes. See IEEE Std 1003.1-2017.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* PIPE_BUF bytes. See IEEE Std 1003.1-2017.
* PIPE_BUF bytes. See write/pwrite in IEEE Std 1003.1-2017.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! incorporated.

@batrick batrick added the core label Nov 9, 2026
@batrick

batrick commented Nov 9, 2026

Copy link
Copy Markdown
Member

Adding core to pickup in a rados run.

2551130 fixed torn log lines on FIFO stderr by writing each line
with a single write(2) per PIPE_BUF chunk, and also set O_NONBLOCK on
stderr. The flag isn't needed for that: writes of up to PIPE_BUF bytes
to a pipe are atomic in blocking mode too, see pipe(7).

And it does harm. The flag lives on the open file description, so when
stdout shares the pipe, as with "2>&1 | less" or subprocess with
stderr=STDOUT, stdout turns non-blocking too, even after we exit. If
the reader falls behind, cout gets EAGAIN and drops the rest of the
output while the tool still exits 0. That's how crushtool's output in
set-choose.t gets cut off on busy make check nodes.

So keep the single-write path, but leave the flags alone. The EAGAIN
handling stays in case someone else made the pipe non-blocking.

Fixes: https://tracker.ceph.com/issues/66997
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov force-pushed the wip-log-stderr-blocking branch from a52f285 to 908b537 Compare November 10, 2026 04:32
@tchaikov

Copy link
Copy Markdown
Contributor Author

changelog:

  • s/See IEEE Std 1003.1-2017/See write/pwrite in IEEE Std 1003.1-2017/ in comment

@batrick

batrick commented Nov 10, 2026

Copy link
Copy Markdown
Member

jenkins test docs

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath8-testing-20261114.052149-main.

@MattyWilliams22

Copy link
Copy Markdown
Contributor

@SrinivasaBharath
SrinivasaBharath merged commit 85097c4 into ceph:main Nov 21, 2026
16 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/44867767723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants