fix(logger): reuse the open log rotator when InitLogger runs again

Every InitLogger call built a new lumberjack rotator and dropped the old
one without closing it, leaking a handle on 3xui.log per call, and
loggers still writing through an old rotator kept it alive. On Windows
the open handles block deleting the file, so
TestInitLoggerConcurrentWithLogging failed its t.TempDir cleanup there.
InitLogger now reuses the open rotator for the same path and closes it
only when the path changes, and the test closes the logger it opened.
Neither half is enough alone: with only one of them the test stays red
on Windows.
This commit is contained in:
MHSanaei
2026-09-27 15:32:20 +02:00
parent 18b337d131
commit 249b38e156
2 changed files with 18 additions and 8 deletions
+1
View File
@@ -36,6 +36,7 @@ func TestGetLogs_ReturnsAtMostC(t *testing.T) {
// logging — CI caught that as a data race between InitLogger and Warningf.
func TestInitLoggerConcurrentWithLogging(t *testing.T) {
t.Setenv("XUI_LOG_FOLDER", t.TempDir())
t.Cleanup(CloseLogger)
stop := make(chan struct{})
var logging sync.WaitGroup