Use mutex when reloading file notifier
This commit is contained in:
parent
3a89201a94
commit
9d72ce2201
1 changed files with 4 additions and 0 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/jouir/pgterminate/base"
|
"github.com/jouir/pgterminate/base"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ type File struct {
|
||||||
handle *os.File
|
handle *os.File
|
||||||
name string
|
name string
|
||||||
sessions chan base.Session
|
sessions chan base.Session
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFile creates a file notifier
|
// NewFile creates a file notifier
|
||||||
|
@ -43,6 +45,8 @@ func (f *File) open() {
|
||||||
|
|
||||||
// Reload closes and re-open the file to be compatible with logrotate
|
// Reload closes and re-open the file to be compatible with logrotate
|
||||||
func (f *File) Reload() {
|
func (f *File) Reload() {
|
||||||
|
f.mutex.Lock()
|
||||||
|
defer f.mutex.Unlock()
|
||||||
log.Println("Re-opening log file", f.name)
|
log.Println("Re-opening log file", f.name)
|
||||||
f.handle.Close()
|
f.handle.Close()
|
||||||
f.open()
|
f.open()
|
||||||
|
|
Loading…
Reference in a new issue