mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
fix(server): address review feedback on SIGHUP log reopening - #5721
Hold the output file mutex across the whole open/swap/close sequence in log.SetOutputFile, so a concurrent call cannot close the file the logger is currently writing to. Also deregister the signal channel when the signaller goroutine exits. Signed-off-by: Aayush7352 <aayushdixit924@gmail.com>
This commit is contained in:
parent
92e768f541
commit
21b363c2bb
@ -27,6 +27,7 @@ func startSignaller(ctx context.Context) func() error {
|
||||
return func() error {
|
||||
var sigChan = make(chan os.Signal, 1)
|
||||
signal.Notify(sigChan, triggerScanSignal, syscall.SIGHUP)
|
||||
defer signal.Stop(sigChan)
|
||||
|
||||
for {
|
||||
select {
|
||||
|
||||
11
log/log.go
11
log/log.go
@ -166,18 +166,17 @@ func SetOutputFile(path string) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), os.ModePerm); err != nil {
|
||||
return fmt.Errorf("creating log file directory: %w", err)
|
||||
}
|
||||
outputFileMu.Lock()
|
||||
defer outputFileMu.Unlock()
|
||||
f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
SetOutput(f)
|
||||
outputFileMu.Lock()
|
||||
prev := outputFile
|
||||
outputFile = f
|
||||
outputFileMu.Unlock()
|
||||
if prev != nil {
|
||||
_ = prev.Close()
|
||||
if outputFile != nil {
|
||||
_ = outputFile.Close()
|
||||
}
|
||||
outputFile = f
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user