From 172aeb2a6f38dbf89463599124afb20df8bcfdc5 Mon Sep 17 00:00:00 2001 From: Aayush7352 Date: Fri, 17 Jul 2026 14:17:28 +0530 Subject: [PATCH] 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. --- log/log.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/log/log.go b/log/log.go index 7e9d30dda..845e3f81a 100644 --- a/log/log.go +++ b/log/log.go @@ -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 }