fix(server): close old log file after swap in SetOutputFile

Swap outputFile before closing the previous file handle, so no
read of outputFile can observe a dangling pointer to a closed
file.  Also wrap the file-open in the mutex (already done) for
atomicity of the entire file rotation sequence.
This commit is contained in:
Aayush7352 2026-07-17 14:17:28 +05:30
parent 21b363c2bb
commit 172aeb2a6f

View File

@ -173,10 +173,11 @@ func SetOutputFile(path string) error {
return err
}
SetOutput(f)
if outputFile != nil {
_ = outputFile.Close()
}
prev := outputFile
outputFile = f
if prev != nil {
_ = prev.Close()
}
return nil
}