Repository navigation
hardening tests and fixes - #998
Open
citizen-stig wants to merge 11 commits into
Open
citizen-stig wants to merge 11 commits into
citizen-stig wants to merge 11 commits into
Conversation
New branch and leaf nodes were written with a raw page pointer and kept alive through deferred_drop_pages until all I/O was drained. If an I/O error made update return early, the nodes could be freed while their writes were still in flight. Let the write command hold an Arc to the node instead, and remove the deferred drop bookkeeping. Co-Authored-By: Claude Opus 5.5 <[email protected]>
LeafUpdater::keep_up_to returned early when there were no cells to keep before the updated key, which skipped reclaiming the overflow pages of the cell being replaced. This happens for the first key of a leaf and for consecutive updated keys, and leaked those overflow pages. Co-Authored-By: Claude Opus 5.5 <[email protected]>
write_ht ignored the results of the page writes, so post-meta truncated the WAL even if some pages never reached the hash table. Drain all writes and return the first error, which keeps the WAL for recovery. Recovery parsed the whole WAL before checking its sequence number, so a WAL left incomplete by a sync that never concluded made opening fail. Read only the header first and discard a WAL from another sync without parsing it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Stop at the manifest's last live record. A crash during an append can leave an incomplete record after it, which recovery used to reject. - Check for gaps in segment IDs only up to the end of the live range, because an interrupted recovery may leave gaps among the segments after it. - Check that live records are contiguous across segment boundaries. The first live record may come after the manifest's start, because that start can be an expired record whose segment was already pruned. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- After truncating, the new end of the live range was the record before the earliest removed delta. When every retained delta was removed, that record had already expired: it either came back after reopening, or pruning failed if its segment was already gone. Use the last retained delta, or nil. - max_rollback_log_len(0) made the rollback sync thread panic on the first commit. Reject it in the setter, like io_workers(0). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Several commit paths returned on the first error while sibling tasks or submitted writes were still running: leaf and branch workers, the I/O completions in update, the bbn/ln fsyncs, the bitbox WAL writeout, and the post-meta cleanup in Sync. Wait for all of them and then return the first error. Also poison the store when a commit unwinds, not only when it returns an error. Ported from 7be9540. Sync::sync changed on master since: it already waits for both preparations before the meta write, so that part is dropped. After the meta write the rollback cleanup is now awaited before the beatree task is joined, so that neither an error from the hash-table writeout nor a panic in the beatree task skips it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Claude Mythos 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_017wb3qEshHAdfkLFsmMCXfc
Each of these fails on master and passes on this branch. - ht_write_error: every hash-table page write past 40 MiB fails (RLIMIT_FSIZE). The commit must report it; before 4eb47b5 it returned Ok and the reopened database had a different root. - overflow_leak: one 256 KiB value rewritten 300 times must not grow the leaf file beyond its first 32 MiB step (bc936da). - commit_panic: a commit that panics after the meta write is durable and a later commit attempt on the same handle must not destroy it (7be9540, poison on unwind). Co-Authored-By: Claude Mythos 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_017wb3qEshHAdfkLFsmMCXfc
The test opened the database on the test thread and moved it, with its open session, into a helper thread for the commit that is expected to fail, so that a hang could be reported. A session is about to be tied to the thread that created it, and the test would no longer compile. Do all the database work on the helper thread. Co-Authored-By: Claude Mythos 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_017wb3qEshHAdfkLFsmMCXfc
citizen-stig
commented
Nov 24, 2026
citizen-stig
commented
Nov 24, 2026
Co-Authored-By: Claude Mythos 5.2 <[email protected]>
Replaces the hand-rolled read loop. The caller only recovers from a non-empty WAL, which is now asserted in debug builds. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
citizen-stig
marked this pull request as ready for review
November 24, 2026 17:39
Co-Authored-By: Claude Mythos 5.2 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Six commits from 2026-10-13 that never reached
master, ported ontomasterat 0224973, plus regression tests for three of them. Five are clean cherry-picks; one needed a manual resolution. One of them fixes a Critical finding of the 2026-11-23 audit: a commit could report success after its hash-table writes had failed.Independent of
nikolai/audit-high-fixes(#997): the two branches merge without conflicts and passcargo test --workspacetogether.Commits
01c08c6 Keep branch and leaf nodes alive in their write commands (from 1512c2b)
What.
IoKind::WriteRaw, which carried a raw page pointer, becomesIoKind::WriteShared, which holds anArcto the node until the write completes. The deferred-drop bookkeeping andFatPage::page()are removed.Why. New nodes were kept alive only until all I/O was drained. If an I/O error made the update return early, they could be freed and their pages reused while their writes were still in flight.
Tested. No dedicated test; covered by the existing suite.
cd7c538 Free overflow pages of a replaced cell with nothing kept before it (from bc936da)
What.
LeafUpdater::keep_up_toreclaims the overflow pages of the replaced cell even when there are no cells to keep before it.Why. It returned early in that case, which happens for the first key of a leaf and for consecutive updated keys, and leaked the pages.
Tested. New
nomt/tests/overflow_leak.rs: one 256 KiB value rewritten 300 times must stay within the leaf file's first 32 MiB step. On master the file grows to 96 MiB.acbb907 Keep the WAL when hash-table writes fail, and recover from a torn WAL (from 4eb47b5)
What.
write_htdrains every submitted page write and returns the first error. WAL recovery reads only the header first (WalBlobReader::read_sync_seqn) and discards a WAL that belongs to another sync without parsing its body.Why. The write results were ignored, so the WAL was truncated even if pages never reached the hash table: the commit returned
Okand the page store was silently corrupt. Separately, a WAL left incomplete by a sync that never concluded made opening fail, although such a WAL is safe to discard.Tested. New
nomt/tests/ht_write_error.rs: withRLIMIT_FSIZEevery hash-table page write past 40 MiB fails while all other writes succeed. On master the commit returnsOkand the reopened database has a different root; here the commit reports the error. The torn-WAL half has no dedicated test.25cd9a3 Harden rollback log recovery (from e52fe48)
What. Recovery stops at the manifest's last live record, checks segment-ID gaps only up to the end of the live range, and checks that live records are contiguous across segments.
Why. A crash during an append can leave an incomplete record after the last live one, which recovery rejected. An interrupted recovery can leave gaps among the segments after the live range.
Tested. The commit adds
recovery_start_live_in_pruned_segmentto the seglog unit tests.5ce119d Fix rollback log edge cases (from e947bdb)
What. After a truncation the new end of the live range is the last retained delta, or nil when none is left.
max_rollback_log_len(0)is rejected in the setter, likeio_workers(0).Why. The end used to be the record before the earliest removed one. When every retained delta was removed, that record had already expired: it came back after reopening, or pruning failed because its segment was gone. A length of zero made the rollback sync thread panic on the first commit.
Tested. No dedicated test; covered by the existing rollback tests.
c6101d7 Drain in-flight work before propagating commit errors (from 7be9540, manual port)
What. Commit paths wait for sibling tasks and submitted writes before returning the first error: leaf and branch workers, the I/O completions in the update, the fsyncs, the WAL writeout and the post-meta cleanup. The store is poisoned when a commit unwinds, not only when it returns an error.
Why. Several paths returned on the first error while other work was still running. A panic inside a commit left the store usable with in-memory state ahead of the disk, and a later commit could then destroy what the panicked one had made durable.
Port note.
Sync::syncchanged onmastersince the original commit: it already waits for both preparations before the meta write, so that part was dropped. After the meta write, the rollback cleanup is now awaited before the beatree task is joined, so that neither a hash-table writeout error nor a beatree panic skips it.Tested. New
nomt/tests/commit_panic.rs: a commit that panics after the meta write is durable, and a later commit attempt on the same handle must not destroy it. Fails on master, passes here.3418450 tests: cover three of the ported hardening fixes
Adds the three test files named above. Each fails on master and passes on this branch.
3dd6615 tests: keep the database on one thread in ht_write_error
The test opened the database on the test thread and moved it, with its open session, into a helper thread.
nikolai/audit-high-fixesmakesSessionnon-Send, and the test would no longer compile there. All database work now happens on the helper thread. The test still fails against master's code.