gc was collecting the lockfile early causing it not to work. fixed with runtime.KeepAlive

This commit is contained in:
sawka 2023-11-09 16:26:44 -08:00
parent 68731f45a2
commit 1a566d06aa
2 changed files with 5 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import (
"os/signal"
"path/filepath"
"regexp"
"runtime"
"runtime/debug"
"strconv"
"strings"
@ -793,7 +794,7 @@ func main() {
scLock, err := scbase.AcquireWaveLock()
if err != nil || scLock == nil {
log.Printf("[error] cannot acquire wave lock: %v\n", err)
log.Printf("[error] cannot acquire wave lock (another instance of wavesrv is likely running): %v\n", err)
return
}
if len(os.Args) >= 2 && strings.HasPrefix(os.Args[1], "--migrate") {
@ -886,4 +887,5 @@ func main() {
if err != nil {
log.Printf("ERROR: %v\n", err)
}
runtime.KeepAlive(scLock)
}

View File

@ -156,7 +156,8 @@ func AcquireWaveLock() (*os.File, error) {
return nil, fmt.Errorf("cannot find/create WAVETERM_HOME directory %q", homeDir)
}
lockFileName := path.Join(homeDir, WaveLockFile)
fd, err := os.OpenFile(lockFileName, os.O_WRONLY|os.O_CREATE, 0600)
log.Printf("[base] acquiring lock on %s\n", lockFileName)
fd, err := os.OpenFile(lockFileName, os.O_RDWR|os.O_CREATE, 0600)
if err != nil {
return nil, err
}