Fix issue #689: Continuous snapshotting every second #691
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.
Summary
This PR fixes a critical bug where Litestream was continuously snapshotting every second instead of respecting the configured intervals, causing excessive S3 transactions (70,000+ overnight as reported).
Fixes #689
Root Cause
When
snapshot.interval
was not specified in the YAML config, the parser would set it to 0 (zero duration) which overwrote the 24h default. This causedtime.Until()
to return a negative duration, triggering immediate and continuous snapshots.Solution
SnapshotConfig
fields to use*time.Duration
pointers to distinguish between "not specified" (nil) and "explicitly set to 0"Changes Made
Configuration validation (
cmd/litestream/main.go
):ErrInvalidSnapshotInterval
,ErrInvalidSnapshotRetention
,ErrInvalidCompactionInterval
,ErrInvalidSyncInterval
ConfigValidationError
type withUnwrap()
forerrors.Is()
supportSnapshotConfig
fields to use*time.Duration
pointersValidate()
method to check all intervals > 0ReadConfigFile
intoOpenConfigFile
(io.ReadCloser) andParseConfig
(io.Reader)Replica configuration (
cmd/litestream/replicate.go
):Comprehensive tests (
cmd/litestream/main_test.go
):t.Run
testsParseConfig
withstrings.NewReader
instead of temp filesTest Plan
✅ All existing tests pass
✅ New tests verify:
Verification
Tested with a config similar to the reported issue:
The sync-interval is properly set to 30m and snapshot interval defaults to 24h (not continuously snapshotting).
🤖 Generated with Claude Code