]> git.hungrycats.org Git - bees/commitdiff
log: clear the output stream error state after each line
authorZygo Blaxell <bees@furryterror.org>
Mon, 31 Aug 2026 20:31:06 +0000 (16:31 -0400)
committerZygo Blaxell <bees@furryterror.org>
Tue, 6 Oct 2026 05:51:40 +0000 (01:51 -0400)
A failed write to the log destination latches badbit on the output
stream, and ostream discards every subsequent insertion for as long as
it stays set.  Nothing in bees ever checks or clears it, so a single
transient write error silences the daemon permanently: it keeps
scanning, deduping and updating its status file, but never writes
another log line, and exits 0 at the end as if nothing happened.

This is not hypothetical.  A test run logging to a virtiofs mount
stopped emitting after five minutes and stayed silent for the next
half hour while continuing to work normally; strace confirmed the
process had stopped issuing writes to the log fd entirely.  The same
binary and configuration logging to local disk ran past that point and
kept going.

The line that hit the error is lost either way, and retrying it risks
blocking behind a destination that is still broken, so drop it and
reset the state instead.  One bad write then costs one line rather
than the remainder of the run.

Assisted-by: Claude-Code:claude-opus-5
src/bees-log.cc

index a95ce0d7d3090c1626334e9ed73a0a3d38ba71fb..3c6d470fcf3920b70999be4a01a3055825608ae0 100644 (file)
@@ -104,6 +104,15 @@ LogQueue::write_line(int level, struct timespec ts,
                        os << (header + body.substr(start) + "\n") << flush;
                        start = body.size();
                }
+               // A failed write to the log destination -- a full filesystem, or
+               // a hiccup on a virtiofs or NFS mount -- latches badbit, and
+               // ostream then discards every later insertion while it stays
+               // set.  bees keeps running and doing work but never logs another
+               // line, with no diagnostic and no exit status to show for it.
+               // The line that hit the error is lost either way, so clear the
+               // state and let the next one through: one bad write costs one
+               // line, not the rest of the run.
+               os.clear();
        }
 }