Repository navigation
Fail the run on write errors to --out-file, --json-out-file or stdout - #729
Conversation
|
🤖 Automated first-pass review — a human maintainer's review is still required before merge. Thanks for this. I went through the diff against master's teardown in
This looks good to merge to me once the release-note point is settled. The |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6614b92. Configure here.
6614b92 to
b1f2969
Compare
|
Good catch. It's real, and it isn't only a BSD issue: glibc already drops the data of a failed write when stdout is line-buffered or unbuffered. In 6614b92, Fixed in b1f2969. The exemption no longer depends on the errno. A gone reader is now recognised when the output is stdout (or an Regular files, devices and any other |
b1f2969 to
bd11821
Compare
|
Thanks. Addressed in bd11821, rebased on e09ee54:
Also in this push: the stdout-pipe exemption for the synthetic |
|
Thanks. Addressed in e5f3683, rebased on e09ee54:
New tests, each checked against a mutant that it kills:
|
main() closed the results file with an unchecked fclose(), and ~json_handler() did the same for the JSON file and then logged "Json file closed.". A buffered ENOSPC/EDQUOT/EIO was lost, so a run whose results were missing or truncated exited 0, and scripts that check the exit code accepted it. Flush and close both files through a new finish_output_file() helper that checks fflush(), ferror() and fclose(). json_handler gets a close() method that returns the error; main() calls it instead of relying on the destructor. On failure memtier prints "error: failed writing --out-file PATH: REASON" (or --json-out-file) and exits 1, the code already used for a run that did not complete. The default stdout output is checked too (`> /dev/full` exited 0), but EPIPE on stdout is not an error: SIGPIPE is ignored, so `| head` makes the writes fail with EPIPE, and that run used to and still exits 0. An explicit --out-file is held to the stricter rule. Also tidy two nits from the #717 review: move the truncate-after-JSON note next to the ftruncate() call, and fix the "allways" typo. Fixes #719 Co-Authored-By: Claude Opus 5.5 <[email protected]>
When stdout is line-buffered or unbuffered (stdbuf -oL / -o0), glibc drops the data of a failed write. The final fflush() then succeeds, only ferror() is set, finish_output_file() returns EIO, and the EPIPE exemption missed: `stdbuf -oL memtier | head` exited 1 with "Input/output error". With default buffering this happened whenever the output was a multiple of BUFSIZ. Decide "the reader went away" from the file type instead: stdout (or an --out-file that is the same file as stdout, e.g. /dev/stdout) on a pipe or socket, with EPIPE or the unknown-cause EIO. A pipe or socket write never fails with EIO itself. Regular files, devices and any other --out-file still fail the run. Document the output-write exit status in README. Co-Authored-By: Claude Opus 5.5 <[email protected]>
finish_output_file() returns a synthetic EIO when stdio dropped the data of a failed write. Its real cause is not only EPIPE: it can be EAGAIN on a full non-blocking pipe (stdout shared with a parent that set O_NONBLOCK) or a socket error, all with a live reader. Exempting every EIO on a stdout pipe or socket hid that data loss: under stdbuf -oL such a run exited 0 with nothing delivered. For EIO, ask the kernel instead: poll(POLLOUT) reports POLLERR on a pipe with no reader and POLLHUP on a closed socket, and neither on a full pipe whose reader is alive. EPIPE and ECONNRESET stay exempt. The check now runs before fclose(), while the fd is open. Tests: a full non-blocking stdout pipe with a live reader must exit 1; the closed-pipe test reuses _closed_pipe_run(); the `| head` test is marked as a best-effort smoke test. README notes the live-reader case and that a connection-stage abort still exits 2. Co-Authored-By: Claude Opus 5.5 <[email protected]>
New tests: an --out-file FIFO whose reader exits fails the run; a full non-blocking stdout pipe with a live reader fails with default buffering too (EAGAIN), not only under stdbuf; a stdout socket whose peer closed (socketpair) or reset (TCP RST) is not an error; and a connection-stage abort still exits 2 when the output write fails. Move the test helpers above their callers and fcntl to the module imports. Note that musl's stdio also drops the data of a failed write. Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_out_file_fifo_reader_exits_is_an_error closed the FIFO's read end after a fixed 0.7 s. On a slow start (e.g. a sanitizer build) that can come before memtier's open(), which then waits for a reader forever. Wait for the "Writing results to FIFO..." line, printed after the open, instead. memtier's stderr now goes to a file so it can be polled, and the helpers clean up their temporary directories. Explain in stdout_reader_gone() why a full non-blocking stdout pipe happens in practice. Co-Authored-By: Claude Opus 5.5 <[email protected]>
e5f3683 to
ef2dcd2
Compare
The background on lost errnos lives in the commit messages; keep the comment to the rule and the O_NONBLOCK case. README now says that the HDR histogram, --client-stats and --failed-keys-file writes are not checked yet. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks. Addressed in ef2dcd2 and 33f437e (head 33f437e, rebased on cde91ea). Point by point:
|
|
Answering the 20:08 version of the review:
|
When memtier was started with stdout (or stderr) closed, the fopen() of --json-out-file got fd 1 (or 2). The text results (or the stderr log lines) were then written into the JSON file, which became invalid, and the run still exited 0. The same applied to --out-file and any other file opened while 0-2 were free. main() now reopens any closed fd 0-2 on /dev/null before it does anything else, the usual idiom for this. A closed stderr only loses the log lines. A closed stdout loses the text results, so if no --out-file was given the run now fails with exit 1 and an error on stderr instead of reporting success for results that went nowhere. The JSON file stays valid in every case. An --out-file, --json-out-file or --failed-keys-file that names a closed fd (/dev/stdout, /dev/fd/1, /proc/self/fd/1, or a symlink to one of them; likewise for stdin and stderr) would now resolve to the reopened /dev/null and lose its output with exit 0, so it is rejected at startup with exit 1, before any of those files is opened. The path is followed one symlink at a time, because an inode comparison cannot tell it from /dev/null itself, which is accepted however it is spelled. Another process's fd (/proc/1/fd/1) is not matched. The closed-stdout error is printed before the other exit-status checks, so it also shows when a connection-stage abort exits 2. After #729 a write to the reopened /dev/null succeeds, so its write-error check no longer sees a closed stdout; the closed-stdout rule here covers that case with the same exit code. The new tests also run in the asan and tsan "misc" cells. Fixes #733 Co-Authored-By: Claude Opus 5.5 <[email protected]>
When memtier was started with stdout (or stderr) closed, the fopen() of --json-out-file got fd 1 (or 2). The text results (or the stderr log lines) were then written into the JSON file, which became invalid, and the run still exited 0. The same applied to --out-file and any other file opened while 0-2 were free. main() now reopens any closed fd 0-2 on /dev/null before it does anything else, the usual idiom for this. A closed stderr only loses the log lines. A closed stdout loses the text results, so if no --out-file was given the run now fails with exit 1 and an error on stderr instead of reporting success for results that went nowhere. The JSON file stays valid in every case. An --out-file, --json-out-file or --failed-keys-file that names a closed fd (/dev/stdout, /dev/fd/1, /proc/self/fd/1, or a symlink to one of them; likewise for stdin and stderr) would now resolve to the reopened /dev/null and lose its output with exit 0, so it is rejected at startup with exit 1, before any of those files is opened. The path is followed one symlink at a time, because an inode comparison cannot tell it from /dev/null itself, which is accepted however it is spelled. Another process's fd (/proc/1/fd/1) is not matched. The closed-stdout error is printed before the other exit-status checks, so it also shows when a connection-stage abort exits 2. After #729 a write to the reopened /dev/null succeeds, so its write-error check no longer sees a closed stdout; the closed-stdout rule here covers that case with the same exit code. The new tests also run in the asan and tsan "misc" cells. Fixes #733 Co-Authored-By: Claude Opus 5.5 <[email protected]>
When memtier was started with stdout (or stderr) closed, the fopen() of --json-out-file got fd 1 (or 2). The text results (or the stderr log lines) were then written into the JSON file, which became invalid, and the run still exited 0. The same applied to --out-file and any other file opened while 0-2 were free. main() now reopens any closed fd 0-2 on /dev/null before it does anything else, the usual idiom for this. A closed stdin or stderr does not fail the run by itself. With stdout closed, the text results would now go to /dev/null. So if no --out-file is given, memtier fails at startup with exit 1 and an error, before connecting or opening any output file, like an --out-file that cannot be opened. After #729 a write to the reopened /dev/null succeeds, so its write-error check would no longer catch this. An --out-file, --json-out-file or --failed-keys-file that names a closed fd (/dev/stdout, /dev/fd/1, /proc/self/fd/1, or a symlink to one of them; likewise for stdin and stderr) would now resolve to the reopened /dev/null and lose its output with exit 0, where master failed with "cannot open". It is rejected at startup with exit 1 too. The path is followed one symlink at a time, because an inode comparison cannot tell it from /dev/null itself, which is accepted however it is spelled. Another process's fd (/proc/1/fd/1) is not matched. The new tests also run in the asan and tsan "misc" cells. Fixes #733 Co-Authored-By: Claude Opus 5.5 <[email protected]>
When memtier was started with stdout (or stderr) closed, the fopen() of --json-out-file got fd 1 (or 2). The text results (or the stderr log lines) were then written into the JSON file, which became invalid, and the run still exited 0. The same applied to --out-file and any other file opened while 0-2 were free. main() now reopens any closed fd 0-2 on /dev/null before it does anything else, the usual idiom for this. A closed stdin or stderr does not fail the run by itself. With stdout closed, the text results would now go to /dev/null. So if no --out-file is given, memtier fails at startup with exit 1 and an error, after the option checks and before connecting or opening any output file, like an --out-file that cannot be opened. After #729 a write to the reopened /dev/null succeeds, so its write-error check would no longer catch this. An --out-file, --json-out-file or --failed-keys-file that names a closed fd (/dev/stdout, /dev/fd/1, /proc/self/fd/1, or a symlink to one of them; likewise for stdin and stderr) would now resolve to the reopened /dev/null and lose its output with exit 0, where master failed with "cannot open". It is rejected at startup with exit 1 too. The path is followed one symlink at a time, because an inode comparison cannot tell it from /dev/null itself, which is accepted however it is spelled. Another process's fd (/proc/1/fd/1) is not matched. The new tests also run in the asan and tsan "misc" cells. Fixes #733 Co-Authored-By: Claude Opus 5.5 <[email protected]>
When memtier was started with stdout (or stderr) closed, the fopen() of --json-out-file got fd 1 (or 2). The text results (or the stderr log lines) were then written into the JSON file, which became invalid, and the run still exited 0. The same applied to --out-file and any other file opened while 0-2 were free. main() now reopens any closed fd 0-2 on /dev/null before it does anything else, the usual idiom for this. A closed stdin or stderr does not fail the run by itself. With stdout closed, the text results would now go to /dev/null. So if no --out-file is given, memtier fails at startup with exit 1 and an error, after the option checks and before connecting or opening any output file, like an --out-file that cannot be opened. After #729 a write to the reopened /dev/null succeeds, so its write-error check would no longer catch this. An --out-file, --json-out-file or --failed-keys-file that names a closed fd (/dev/stdout, /dev/fd/1, /proc/self/fd/1, or a symlink to one of them; likewise for stdin and stderr) would now resolve to the reopened /dev/null and lose its output with exit 0, where master failed with "cannot open". It is rejected at startup with exit 1 too. The path is followed one symlink at a time, because an inode comparison cannot tell it from /dev/null itself, which is accepted however it is spelled. Another process's fd (/proc/1/fd/1) is not matched. The same check covers the input paths --data-import, --monitor-input, --cert, --key and --cacert: with stdin closed, /dev/stdin would now read an empty /dev/null. All path checks run right after option parsing, before any of these files is opened or read. The new tests also run in the asan and tsan "misc" cells. Fixes #733 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-file The --hdr-file-prefix files, the --client-stats CSVs and --failed-keys-file were written without checking for errors: the HDR writers and save_csv() ignored fclose(), and the failed-keys logger checked fprintf() (which only fills the stdio buffer) but not the fflush() that does the write. On a full disk, quota or I/O error the files ended up empty or truncated, nothing was printed and memtier exited 0. A file that could not be opened was reported but also exited 0. These files now follow the rule #729 set for --out-file and --json-out-file. They are flushed and checked with ferror() through finish_output_file(), and a failure prints "error: failed writing --hdr-file-prefix file PATH: REASON" (or --client-stats file, or --failed-keys-file PATH) or "error: cannot open ...". The other files are still written, and memtier exits 1 (a connection-stage abort keeps exit code 2). g_output_failed replaces main()'s local output_failed so run_benchmark() can set it for the CSVs. --failed-keys-file is fatal too, open failure included: it is an output that was asked for, and a lost log with exit 0 is what #719 fixed for the other outputs. The run is not cut short: as before, logging stops and the benchmark goes on; the exit code reports it. stdout_reader_gone() moves to file_io.cpp so a --failed-keys-file on stdout whose reader went away (/dev/stdout and `| head`) gets the same exemption as the results on stdout. Release notes: such runs now exit 1 instead of 0, including an HDR or --client-stats path in a missing directory and a --failed-keys-file that cannot be opened. That message is now "error: cannot open --failed-keys-file PATH: REASON; logging disabled." instead of a warning. Tests: /dev/full symlinks for the full-run and per-command .txt and .hgrm files and for a --client-stats CSV, --failed-keys-file /dev/full with SETs that fail with -OOM, and a --failed-keys-file on a closed stdout pipe. Fixes #744 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-file The --hdr-file-prefix files, the --client-stats CSVs and --failed-keys-file were written without checking for errors: the HDR writers and save_csv() ignored fclose(), and the failed-keys logger checked fprintf() (which only fills the stdio buffer) but not the fflush() that does the write. On a full disk, quota or I/O error the files ended up empty or truncated, nothing was printed and memtier exited 0. A file that could not be opened was reported but also exited 0. These files now follow the rule #729 set for --out-file and --json-out-file. They are flushed and checked with ferror() through finish_output_file(), and a failure prints "error: failed writing --hdr-file-prefix file PATH: REASON" (or --client-stats file, or --failed-keys-file PATH) or "error: cannot open ...". The other files are still written, and memtier exits 1 (a connection-stage abort keeps exit code 2). g_output_failed replaces main()'s local output_failed so run_benchmark() can set it for the CSVs. --failed-keys-file is fatal too, open failure included: it is an output that was asked for, and a lost log with exit 0 is what #719 fixed for the other outputs. The run is not cut short: as before, logging stops and the benchmark goes on; the exit code reports it. stdout_reader_gone() moves to file_io.cpp so a --failed-keys-file on stdout whose reader went away (/dev/stdout and `| head`) gets the same exemption as the results on stdout. Release notes: such runs now exit 1 instead of 0, including an HDR or --client-stats path in a missing directory and a --failed-keys-file that cannot be opened. That message is now "error: cannot open --failed-keys-file PATH: REASON; logging disabled." instead of a warning. Tests: /dev/full symlinks for the full-run and per-command .txt and .hgrm files and for a --client-stats CSV, --failed-keys-file /dev/full with SETs that fail with -OOM, and a --failed-keys-file on a closed stdout pipe. Fixes #744 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-file The --hdr-file-prefix files, the --client-stats CSVs and --failed-keys-file were written without checking for errors: the HDR writers and save_csv() ignored fclose(), and the failed-keys logger checked fprintf() (which only fills the stdio buffer) but not the fflush() that does the write. On a full disk, quota or I/O error the files ended up empty or truncated, nothing was printed and memtier exited 0. A file that could not be opened was reported but also exited 0. These files now follow the rule #729 set for --out-file and --json-out-file. They are flushed and checked with ferror() through finish_output_file(), and a failure prints "error: failed writing --hdr-file-prefix file PATH: REASON" (or --client-stats file, or --failed-keys-file PATH) or "error: cannot open ...". The other files are still written, and memtier exits 1 (a connection-stage abort keeps exit code 2). g_output_failed replaces main()'s local output_failed so run_benchmark() can set it for the CSVs. --failed-keys-file is fatal too, open failure included: it is an output that was asked for, and a lost log with exit 0 is what #719 fixed for the other outputs. The run is not cut short: as before, logging stops and the benchmark goes on; the exit code reports it. stdout_reader_gone() moves to file_io.cpp so a --failed-keys-file on stdout whose reader went away (/dev/stdout and `| head`) gets the same exemption as the results on stdout. Release notes: such runs now exit 1 instead of 0, including an HDR or --client-stats path in a missing directory and a --failed-keys-file that cannot be opened. That message is now "error: cannot open --failed-keys-file PATH: REASON; logging disabled." instead of a warning. Tests: /dev/full symlinks for the full-run and per-command .txt and .hgrm files and for a --client-stats CSV, --failed-keys-file /dev/full with SETs that fail with -OOM, and a --failed-keys-file on a closed stdout pipe. Fixes #744 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-file The --hdr-file-prefix files, the --client-stats CSVs and --failed-keys-file were written without checking for errors: the HDR writers and save_csv() ignored fclose(), and the failed-keys logger checked fprintf() (which only fills the stdio buffer) but not the fflush() that does the write. On a full disk, quota or I/O error the files ended up empty or truncated, nothing was printed and memtier exited 0. A file that could not be opened was reported but also exited 0. These files now follow the rule #729 set for --out-file and --json-out-file. They are flushed and checked with ferror() through finish_output_file(), and a failure prints "error: failed writing --hdr-file-prefix file PATH: REASON" (or --client-stats file, or --failed-keys-file PATH) or "error: cannot open ...". The other files are still written, and memtier exits 1 (a connection-stage abort keeps exit code 2). g_output_failed replaces main()'s local output_failed so run_benchmark() can set it for the CSVs. --failed-keys-file is fatal too, open failure included: it is an output that was asked for, and a lost log with exit 0 is what #719 fixed for the other outputs. The run is not cut short: as before, logging stops and the benchmark goes on; the exit code reports it. stdout_reader_gone() moves to file_io.cpp so a --failed-keys-file on stdout whose reader went away (/dev/stdout and `| head`) gets the same exemption as the results on stdout. Release notes: such runs now exit 1 instead of 0, including an HDR or --client-stats path in a missing directory and a --failed-keys-file that cannot be opened. That message is now "error: cannot open --failed-keys-file PATH: REASON; logging disabled." instead of a warning. Tests: /dev/full symlinks for the full-run and per-command .txt and .hgrm files and for a --client-stats CSV, --failed-keys-file /dev/full with SETs that fail with -OOM, and a --failed-keys-file on a closed stdout pipe. Fixes #744 Co-Authored-By: Claude Opus 5.5 <[email protected]>

Problem
If writing the results fails (disk full, quota, I/O error), memtier prints no error and exits 0. A script that checks the exit code then accepts a missing or truncated results file as a good run. This affects
--out-file,--json-out-file, and the default stdout output (> /dev/full). In the JSON case memtier even logsJson file closed.Root cause
--out-file:main()closed the file with an uncheckedfclose(outfile). Thefprintf()results andferror()were never checked either, so the bufferedENOSPCwas lost. Results on stdout were never flushed or checked at all.--json-out-file:~json_handler()calledfclose(m_json_file)without checking it and loggedJson file closed.whatever happened.Fix
finish_output_file(FILE *, bool do_close)infile_io.cpp. It runsfflush(), thenferror(), then (optionally)fclose(), and returns 0 or an errno value. If an earlier write failed and its errno is gone, it returnsEIO.json_handler::close()closes the nesting and the file and returns the error.main()calls it. The destructor still calls it for the early-exit paths (which ignore the result).Json file closed.is logged only when the close succeeds.main()printserror: failed writing --out-file PATH: REASON(or--json-out-file PATH, orresults to stdout) and returns 1. That is the code already used for a run that did not complete (g_worker_failed). A connection-stage abort still returns 2 first.memtier ... | headmakes the writes fail withEPIPE. That run exited 0 before and still does.fflush()then succeeds, onlyferror()is left, and theEPIPEis gone. With default buffering the same thing happens when the output is a multiple ofBUFSIZ.EIOcan also hide real data loss on a live reader:EAGAINon a full non-blocking pipe (stdout shared with a parent that setO_NONBLOCK), or a socket error. SoEIOalone is not enough to exempt the run.stdout_reader_gone(). It runs beforefclose(), while the fd is still open. The output must be stdout, or an--out-filethat is the same file as fd 1 (byst_dev/st_ino, e.g./dev/stdout), and it must be a pipe or socket (fstat). Then:EPIPEorECONNRESETmeans the reader is gone, so the run is not failed.EIO, the kernel decides:poll(POLLOUT, 0)reportsPOLLERRon a pipe with no reader andPOLLHUPon a closed socket. A full pipe with a live reader reports neither, so the run fails.EBADF), a live reader that lost data, any other--out-file(e.g. a FIFO whose reader exits), and--json-out-file.main()says so.--client-statsCSV files and--failed-keys-filestill close unchecked. That is left for a follow-up.--helpand the man page (generated from--help) have no exit-status section, so they are unchanged.ftruncate()call, and the "allways" typo is fixed.Tests
The PR evolved in three steps, all on this branch:
EPIPEerrno that may be lost.EIOis exempt only whenpoll()reports that the reader is gone.468f3af, ef2dcd2 and 33f437e add only tests, comments and README text. There are 11 new test functions in
tests/tests_oss_simple_flow.py. Tests skip when/dev/full,stdbufor/dev/stdoutis missing.stdbufruns setASAN_OPTIONS=verify_asan_link_order=0so ASan builds accept itsLD_PRELOAD.test_out_file_write_error(--out-file /dev/full)test_json_out_file_write_error(--json-out-file /dev/full)test_stdout_write_error(stdout on/dev/full)test_connection_stage_abort_keeps_rc_2_on_write_error(wrong password,--connection-stage-timeout=1,--out-file /dev/full: rc 2 and the output error printed)test_out_file_fifo_reader_exits_is_an_error(--out-fileFIFO with--test-time 2; the reader is closed once memtier printsWriting results to FIFO..., i.e. after its open(): rc 1,Broken pipe)test_stdout_closed_pipe_is_not_an_error(stdout pipe, reader already closed)EPIPEexemptiontest_stdout_closed_pipe_unbuffered_is_not_an_error(same understdbuf -o0/-oL)EPIPEhandlingtest_stdout_reader_exits_early(stdbuf -oL memtier | head -n 1). A best-effort smoke test: it is timing-dependent and caught the first version's bug in 27/30 runs.EPIPEhandlingtest_out_file_dev_stdout_closed_pipe_is_not_an_error(--out-file /dev/stdout, closed pipe)test_stdout_closed_socket_is_not_an_error(stdout socketpair with closed peer, and a TCP connection reset by its peer, with default buffering andstdbuf -o0)S_ISSOCK,ECONNRESETtest_stdout_full_nonblocking_pipe_is_an_error(fullO_NONBLOCKstdout pipe with a live reader, default buffering (EAGAIN) andstdbuf -oL(syntheticEIO): rc 1)The TCP-reset case binds an ephemeral 127.0.0.1 port, so it cannot collide with other tests.
Mutation check (
--env oss). I ran the 4 newest tests against mutants of the final code, and each mutant is killed:--out-fileexempt)test_out_file_fifo_reader_exits_is_an_errortest_stdout_full_nonblocking_pipe_is_an_errorECONNRESETnot exempttest_stdout_closed_socket_is_not_an_errorS_ISSOCKdroppedtest_stdout_closed_socket_is_not_an_errortest_connection_stage_abort_keeps_rc_2_on_write_errorEarlier steps of this PR, also measured:
test_stdout_closed_pipe_unbuffered_is_not_an_error,test_stdout_reader_exits_earlyandtest_out_file_dev_stdout_closed_pipe_is_not_an_errorin 3/3 runs.test_stdout_full_nonblocking_pipe_is_an_error(stdbuf case) in 3/3 runs.Rates:
--env ossand in 3/3 runs with an ASan build (--enable-sanitizers,detect_leaks=1, no sanitizer reports). They also pass on--env oss-cluster --shards-count 3.tests_oss_simple_flow.pypasses (58/58). The 11 tests pass again after rebasing on cde91ea.Manual matrix with this PR (the first version's result in brackets):
macOS: CI there only builds and runs
make check, and thestdbuftests skip. BSD stdio keeps unwritten data in the buffer after a failed write, so the finalfflush()reportsEPIPEagain and theEIO/poll()branch is not normally reached.POLLERRon a pipe without a reader is Linux behaviour; neither POSIX nor macOSpoll(2)documents it. If theEIObranch is reached on macOS andpoll()reports neitherPOLLERRnorPOLLHUP, the run fails (rc 1). That is the safe direction: data loss is never hidden. Not checked by hand on macOS.Release notes
error: failed writing --out-file PATH: REASON(or--json-out-file PATH, orresults to stdout) when the results cannot be written, for example on a full disk. This also applies after a graceful Ctrl+C/SIGTERM. Before, such a run exited 0 and left a missing or truncated results file.--out-filethat is stdout, such as/dev/stdout) is a pipe or socket whose reader has gone away (e.g.| head), the run still exits 0.Resource temporarily unavailable(orInput/output errorwith line-buffered stdout). The output really was incomplete; if a CI job starts failing this way, write the results with--out-fileinstead.Saving JSON output file/Json file closed.are printed, so with2>&1the report lines now come before those two stderr lines.>&-) and the results going to stdout now exits 1 (Bad file descriptor); it used to exit 0.Affected versions
1.0.0 (
--out-file) / 1.2.9 (--json-out-file) through 2.5.2 (latest) and master.fclose(outfile), and by fb6888d ("add support for JSON output (add support for JSON output #18)", first tag 1.2.9).Fixes #719
🤖 Generated with Claude Code
Note
Medium Risk
Changes exit-code behavior for scripts and CI that assumed exit 0 on write failures; the stdout exemption logic is subtle but well-tested.
Overview
memtier_benchmark now fails the run when results cannot be written, instead of exiting 0 with missing or truncated output. A shared
finish_output_file()flushes and optionally closes output streams and surfaces write/close errors;main()uses it for--out-fileand stdout, andjson_handler::close()uses it for--json-out-file(loggingJson file closed.only on success). Failures print a clear stderr message and return exit code 1, including after graceful interrupt; connection-stage abort still returns 2 first.The stdout pipe/socket reader-gone case (
| head, etc.) stays exit 0 viastdout_reader_gone(): stdout or--out-filethat is the same inode as stdout, on a pipe/socket, withEPIPE/ECONNRESET, or syntheticEIOonly whenpoll()shows the reader is gone. Other paths (regular files, FIFOs, full live pipes) still fail.README documents output write errors and exit status. 12 integration tests cover
/dev/full, FIFO reader exit, closed pipes/sockets, and non-blocking full pipes.Reviewed by Cursor Bugbot for commit ef2dcd2. Bugbot is set up for automated code reviews on this repo. Configure here.