fix: recover from missing .active file during rotation (#386)#399
Merged
Conversation
If the active trace file or its parent directory is removed externally (operator, log rotation, container teardown), `RotatingWriter::rotate()` fails at `fs::rename(.active, .bin)` or `File::create(new_path)`. Before this fix the error propagated out of `drained()` without advancing `next_drain_time` / `next_rotation_time`, so `should_drain()` kept firing on every 5ms flush-loop tick — busy loop. Recovery: - Advance both timers up front in rotate() so any failure below cannot cause busy-spinning. - Tolerate NotFound from the rename: log a rate-limited warning, skip pushing to closed_files, and start a fresh segment. - Tolerate NotFound from File::create by retrying create_dir_all once. - On any unrecoverable error, mark the writer Finished so it stops cleanly instead of retrying every cycle. - Apply the same NotFound tolerance to finalize().
Fluzko
reviewed
May 13, 2026
| }; | ||
| let writer = BufWriter::new(file); | ||
| self.state = Self::prepare_segment(writer)?; | ||
| self.state = match Self::prepare_segment(writer) { |
Contributor
There was a problem hiding this comment.
with a fail on this we would be leaving an orphan file created @479 and an inconsistent state. No big deal, but probably worth to take into account
Member
There was a problem hiding this comment.
Agreed, it would be good to remove the file inside our error handling block.
jlizen
approved these changes
May 13, 2026
| }; | ||
| let writer = BufWriter::new(file); | ||
| self.state = Self::prepare_segment(writer)?; | ||
| self.state = match Self::prepare_segment(writer) { |
Member
There was a problem hiding this comment.
Agreed, it would be good to remove the file inside our error handling block.
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.
If the active trace file or its parent directory is removed externally (operator, log rotation, container teardown),
RotatingWriter::rotate()fails atfs::rename(.active, .bin)orFile::create(new_path). Before this fix the error propagated out ofdrained()without advancingnext_drain_time/next_rotation_time, soshould_drain()kept firing on every 5ms flush-loop tick — busy loop.Recovery:
Fixes #386