Repository navigation
Stop snapshots taken in the same millisecond overwriting each other - #2
Merged
Merged
Conversation
snapshot() named each file from the wall clock to the millisecond with no uniqueness check, so two snapshots inside one millisecond resolved to one name and the second overwrote the first. Twenty-five stamps read straight from the clock in a tight loop can be a single distinct value. It is reachable rather than theoretical. The auto-snapshot timer and a manual save can land together, and on hardware that finishes a backup in under a millisecond any repeated snapshot hits it. A snapshot someone took could be silently replaced by the next one. Names now come from a stamp source that steps past the last value it handed out, and the destination is claimed with O_CREAT | O_EXCL so a second process working the same case cannot be given a name this one just took. A failed backup removes the file it claimed rather than leaving an empty one for list_snapshots to report. The stamp is floored to the millisecond before it is compared. Tracking the raw reading instead would let a clock that advanced by less than a millisecond pass the check and still format to the string already used, which the retry loop survives only by spending attempts. The name format is unchanged, so _NAME_RE still recovers labels and the auto flag. Two tests, each failing without the part it covers: one on the stamp source under a clock that creeps 100 microseconds per read, one taking real snapshots through the same clock. test_backup_prune_keeps_recent was failing on faster machines for this reason and now passes. Co-Authored-By: Claude Fable 5 <[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.
backup.snapshot()named each file from the wall clock to the millisecond with no uniqueness check:Twenty-five of those generated in a tight loop produce one distinct string. Two snapshots landing in the same millisecond resolved to the same filename and the second overwrote the first, so a snapshot someone took could be silently replaced by the next one.
It is reachable rather than theoretical. The auto-snapshot timer and a manual save can land together, and on hardware that finishes a backup in under a millisecond any repeated snapshot hits it. This is why
test_backup_prune_keeps_recentfails on a fast machine (16 snapshots where it expects 20) and passes on the CI runner, which is slow enough that names do not collide.The fix
Stamps now come from a source that steps past the last value it handed out, and the destination is claimed with
O_CREAT | O_EXCLso a second GLEAPP process working the same case cannot be handed a name this one just took. A failed backup removes the file it claimed rather than leaving an empty one behind forlist_snapshotsto report as real.The stamp is floored to the millisecond before it is compared. Comparing raw readings instead lets a clock that advanced by less than a millisecond pass the check and still format to the string already used. The retry loop survives that, but only by spending attempts, and a clock advancing more slowly than the loop runs would spend the whole budget inside one millisecond and fail the snapshot outright.
The name format is unchanged, so
_NAME_REstill recovers labels and the auto flag. Verified by round trip: 6 snapshots, 6 distinct names, labels and auto flags intact.Tests
Two, because they catch different things. Both are driven by a clock that creeps 100 microseconds per read, which puts ten reads in every millisecond on any machine, so neither passes or fails by hardware.
Run against three versions of the module:
maintest_snapshot_stamps_never_repeat_under_a_creeping_clocktest_snapshots_in_one_millisecond_do_not_overwriteThe middle column is the point. An earlier version of this fix passed the integration test and was still wrong, because the retry loop hid the repeating stamp. The unit test on the stamp source is what catches it.
Full suite is 64 passed, up from 62 with one of those failing locally. Lint reports no new warnings.