Review report

core: PR #35763

4 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · The failure test does not verify that a failed write preserves the existing banlist

Because the test removes the valid banlist before forcing the rename failure, it never checks that a failed update leaves the last good banlist readable.

Location: src/test/banman_tests.cpp:69 (head).

Details and suggested fix

The rename-failure case removes the valid banlist_atomic.json created by the roundtrip and replaces it with a directory before calling Write. No valid destination remains to check. A regression that truncated the destination before staging and then failed against the directory could still pass. Add a separate case that keeps the valid JSON file, creates a directory at banlist_atomic.json.tmp so opening the temporary file fails, and calls Write with a different ban map. Check that Write returns false and that Read still returns only the original 203.0.113.1/32 entry. Keep the existing rename-failure case as well.


Link

[suggestion] · The temporary JSON file is renamed into place without being synced to disk

On some filesystems, power loss can leave settings.json or banlist.json empty or stale; this is a pre-existing durability gap, not a regression.

Location: src/common/settings.cpp:153 (head).

Details and suggested fix

WriteSettings writes and closes the .tmp file, then replaces the destination with a plain rename. It does not sync the file data or the parent directory. This protects against write failures and process termination, but on filesystems that can persist the rename before the file data, an OS crash or power loss can leave the destination empty or stale. An unreadable settings.json stops startup, while an unreadable banlist.json causes BanMan to recreate an empty ban list. Whether this occurs depends on the filesystem and mount options. Is the intended guarantee limited to process-level interruption? If it should cover power loss, write the temporary file with fsbridge::fopen and AutoFile, call Commit() before closing and renaming, and optionally call DirectoryCommit on the parent; this adds an fsync for each settings or banlist write. Otherwise, narrow the comment and PR text to write failures and process interruption.


Link

[suggestion] · The helper name does not match the name promised in the PR description

The PR text says the helper was renamed to common::WriteJson, but the declaration, definition, documentation, and callers still use WriteSettings.

Location: src/common/settings.h:48 (head).

Details and suggested fix

The description says common::WriteSettings was renamed to common::WriteJson, but the code retains WriteSettings in settings.h and settings.cpp, and both CBanDB::Write and ArgsManager::WriteSettingsFile still call it. The comment describes writing a settings file, although the helper also writes banlist.json and the error strings refer to a JSON file. Either complete the rename, including the declaration, definition, callers, and comment, or remove the rename claim from the PR title and description.


Link

[suggestion] · The directory-iterator variable shadows the test's CBanEntry variable

The loop reuses the name of a ban entry declared earlier in the test, contrary to the project's guidance to avoid variable shadowing.

Location: src/test/banman_tests.cpp:75 (head).

Details and suggested fix

write_uses_rename declares CBanEntry entry near the start of the test. The temporary-file counting loop then declares another entry, shadowing the first variable within the loop. Rename the loop variable, for example to dir_entry, to avoid the shadowing.


Coverage details

Earlier concerns

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