fix(doltserver): rotate dolt-server.log at startup to cap size#3161
Merged
Conversation
The dolt sql-server's stdout/stderr is captured directly to .beads/dolt-server.log with no rotation, leading to field reports of the file reaching 379 MB. Since dolt owns the file descriptor, we cannot interpose a size-limiting writer at runtime without a streaming goroutine, so implement the simplest fix that works: a startup-time size check that renames the log to .log.1 (overwriting any previous rotation) when it exceeds a configurable ceiling, defaulting to 50 MB and overridable via BEADS_DOLT_LOG_MAX_BYTES. Rotation is best-effort and never blocks startup: failures are logged via debug.Logf and the server proceeds to open the existing log. This is startup-only; a long-running server whose log grows past the cap mid-run will not be rotated until the next restart. Tests cover the rotate/leave-alone/overwrite/missing/disabled paths, the env-var override parsing, and the higher-level maybeRotateLog wrapper against the production logPath helper.
maphew
approved these changes
Apr 10, 2026
maphew
left a comment
Collaborator
There was a problem hiding this comment.
Thanks @quad341 — nice defensive implementation. Best-effort rotation that never blocks startup, single-generation retention is pragmatic, env var escape hatch for the threshold. 8 test cases cover the edges well.
The Windows os.Rename / MoveFileEx comment is a nice touch.
Approved.
🤖 Reviewed with Claude Code
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.
Problem
`dolt-server.log` grows unbounded with no rotation. Field report: 379 MB at one site (with verbose connection logging — even after that's reduced, the log still needs a hard cap).
Fix
Startup-only rotation. At each `Start()`, if `dolt-server.log` exceeds the threshold, rotate it to `dolt-server.log.1` (overwriting any previous rotated file) and open a fresh log.
Why startup-only: true runtime rotation would require either a streaming goroutine owning the dolt server stdout/stderr pipe (significant restructuring) or copy-truncate (which races with the child's append writes). Startup rotation is sufficient for the field report's needs and documented at the top of `logrotate.go`.
Tests
All passing. `go vet` clean. `gofmt` clean.