4 suggestions
Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.
Optional improvements
[suggestion] · Pending-byte discard() behavior is untested
The new failure test would still pass with a no-op discard(); no current block or undo serializer that throws with bytes pending was identified.
Location: src/test/streams_tests.cpp:755 (head).
Details and suggested fix
With capacity one, write("00"_hex) flushes automatically; with capacity two, the explicit flush() does it. Both clear m_buf_pos through std::exchange before the destination throws, so neither the attempt-count assertion nor the destructor's Assume exercises abandonment. Add a recording-stream case with capacity two: write one byte, call discard(), then flush(), and let the writer be destroyed. Assert zero write_buffer() calls to protect the documented promise that pending bytes can be abandoned without writing them.
[suggestion] · Block and undo write-error handlers lack automated coverage
Automated write-failure coverage stops at BufferedWriter, leaving the new storage handlers' fatal notifications, failure returns, and undo-status update boundary untested.
Location: src/node/blockstorage.cpp:1180 (head).
Details and suggested fix
buffered_writer_flush_failure exercises only a mock destination, while the existing blockmanager_tests exercise successful writes. Neither checks what happens after a destination write fails inside either new handler. Add a test-only way to inject a write_buffer() failure through BlockManager, after allocation and opening succeed. Check that WriteBlock returns a null FlatFilePos, and that WriteBlockUndo returns false with an error state, emits the fatal notification, and leaves BLOCK_HAVE_UNDO unset for a block without existing undo data. Check the block notification too. This requires a new test seam because the writers construct AutoFile directly and write_buffer() is non-virtual. A failure only at fclose() would exercise a different path.
[suggestion] · The handler invariant and its cleanup arrive separately
Folding 1584299 into 1c33fa05 would present the handlers, destructor invariant, and abandonment mechanism together; no valid serialization input triggering the intermediate pending-byte case was identified.
Location: src/node/blockstorage.cpp:1016 at 1c33fa05dfe8 (commit) (commit).
Details and suggested fix
1c33fa05dfe8a87444eebfdc0436d7cea3761600 adds both write-error handlers and the destructor's empty-buffer Assume, but declares each writer inside try. Such a writer is destroyed before its handler can abandon a buffered prefix. 1584299ae51d5c0bb821f4f51521ec6eaf9bdfbd then moves the writers outside try, narrows the catches from std::runtime_error to std::ios_base::failure, and adds discard() before closing the files.
Fold the latter commit into the former so the invariant and abandonment mechanism arrive as one reviewable change. The intervening aade8e8a377c383b59b02beef4372e3214310231 only changes comments. Keep a27c5f6c83a1cdd0c1b4ba4a39bfa93916a61c0e as the characterization-test commit and a4199b39f92c3e572196f464a067f70b1d77cda5 as the separate no-retry fix. Base already flushed pending bytes during destruction, so this is a review-flow suggestion, not a claim of an observed intermediate failure or a head defect.
[suggestion] · The no-retry safety rationale arrives after the behavior change
The flush() change in a4199b39 discards pending bytes before writing, but its data-safety rationale appears only in the later comment-only commit aade8e8.
Location: src/streams.h:705 at a4199b39f92c (commit) (commit).
Details and suggested fix
a4199b39f92c3e572196f464a067f70b1d77cda5 changes flush() to clear m_buf_pos with std::exchange before calling write_buffer(). Its message explains avoiding a destructor retry during unwinding, but not why replaying the retained buffer would be unsafe. aade8e8a377c383b59b02beef4372e3214310231 adds precisely that explanation: the stream may have obfuscated the buffer in place, and a short write may already have written a prefix. Fold this comment-only commit into the no-retry commit so reviewers can assess the discard-on-failure contract without looking ahead. The explanation depends only on existing AutoFile::write_buffer() behavior, so this preserves the standalone stream fix and leaves final behavior unchanged.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [suggestion]: Destructor fallback retains an undocumented termination path (earlier report)
- [suggestion]: Short-write diagnostics omit the operating-system error (earlier report)
Background
Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.
Documented decisions
#31551 introduced buffering to improve serialization throughput and permit obfuscation directly in an owned, mutable buffer, avoiding the extra copying required for immutable write input. Its stated motivation was performance, not write-error recovery.
The mutable buffer is central to the failure-contract question: it was deliberately available for AutoFile to transform in place, rather than being an immutable copy retained for replay. The inspected proposal and commit message do not describe retry guarantees after that transformation or a partial write.