streams: handle buffered write failures outside the destructor

bitcoin/bitcoin: PR #36049

1 suggestion

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Block and undo write-error handlers lack regression coverage

buffered_writer_flush_failure never calls WriteBlock or WriteBlockUndo, leaving their write-error cleanup, fatal notifications, failure returns, and undo-status handling without regression coverage.

Location: src/node/blockstorage.cpp:1175 (head).

Details and suggested fix

The fake stream covers both automatic and final flush failures, while the blockmanager tests only write successfully. The writer destructor's Assume can detect an omitted final flush in Debug builds, but those successful writes cannot exercise the new catch blocks.

Add a test-only fault-injection seam, since both writers construct their AutoFile internally, and inject a write failure after allocation and opening. Exercise each writer directly and assert file closure and a fatal notification. Check that WriteBlock returns a null FlatFilePos, and that WriteBlockUndo returns false, sets state.IsError(), and leaves BLOCK_HAVE_UNDO unset. Initialize the undo fixture's cursor/file metadata and supply an index with a null undo position and a valid parent so it reaches the write. Cover both a final partial-buffer flush and an automatic full-buffer flush, including a failure after an earlier successful flush to check explicit closing of a previously written file. An open failure would exercise a different handler.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.