Uh oh!
There was an error while loading. Please reload this page.
fix(log): await cleanup and sort files before deletion - #7245
Conversation
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found one potentially related PR: Related PR:
This PR also addresses log file deletion issues, which may be related to the race condition and deletion logic being fixed in PR #7245. You may want to verify if this PR is addressing a symptom of the same underlying bugs (race condition and improper file sorting) that PR #7245 fixes. No other duplicate PRs found addressing the same cleanup/sort/race condition issues. |
djnawara
commented
Jan 7, 2026
FYI spent some time on this today because I'm working on a plugin and saw that my log was deleted while i still had the handle open. I pinged #6641 because this is very closely related. |
Also, I used this script to prove out the race. I would just boot the TUI via this script, and then exit immediately. After a few tries, it shows up. Also note that you sometimes get 2 log files, because |
- Await cleanup() in init() to prevent race condition where cleanup could run concurrently with file creation - Sort files before slicing to ensure oldest files are deleted, not arbitrary files based on filesystem order The glob scan returns files in arbitrary order, so slice(0, -10) was deleting random files instead of the oldest ones. Adding sort() ensures lexicographic order which matches chronological order for the YYYY-MM-DDTHHMMSS.log filename format.
f1ae801 to
08fa7f7CompareClosing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
Summary
cleanup()ininit()to prevent race condition where cleanup could run concurrently with file creationProblem
Log files were being deleted immediately after creation due to two issues:
cleanup()was called fire-and-forget (not awaited), creating a race conditionBun.Glob.scan()returns files in arbitrary filesystem order, soslice(0, -10)was deleting random files instead of the oldest onesFix
awaitbeforecleanup()call.sort()before.slice(0, -10)to ensure lexicographic order (which matches chronological order for theYYYY-MM-DDTHHMMSS.logfilename format)Tests
Added 8 tests covering: