diff --git a/app/cli.go b/app/cli.go index b63802f..41d8fc9 100644 --- a/app/cli.go +++ b/app/cli.go @@ -45,7 +45,7 @@ func (r Request) ResponsePath() string { func Send(data Request) { pipePath := PipePath() - pipe, err := os.OpenFile(pipePath, os.O_APPEND, os.ModeNamedPipe) + pipe, err := os.OpenFile(pipePath, os.O_RDWR, os.ModeNamedPipe) if err != nil { log.Println("Failed to open", pipePath, ":", err) log.Fatalln("Is the reaction daemon running? Does the CLI run as the same user?") diff --git a/app/pipe.go b/app/pipe.go index 731659f..71b81c6 100644 --- a/app/pipe.go +++ b/app/pipe.go @@ -3,11 +3,11 @@ package app import ( "encoding/gob" "errors" - "io/fs" "log" "os" "sync" "syscall" + "time" "gopkg.in/yaml.v3" ) @@ -111,7 +111,7 @@ func (r ReadableMap) ToString() string { // Pipe-related, server-related functions -func createOpenPipe() fs.File { +func createOpenPipe() *os.File { err := os.Mkdir(RuntimeDirectory(), 0755) if err != nil && !errors.Is(err, os.ErrExist) { log.Fatalln("FATAL Failed to create runtime directory", err) @@ -156,7 +156,19 @@ func Serve() { var request Request err := gob.NewDecoder(pipe).Decode(&request) if err != nil { - log.Println("WARN Invalid Message received: ", err) + d, _ := time.ParseDuration("1s") + if err.Error() == "EOF" { + log.Println("DEBUG received EOF, seeking one byte") + _, err = pipe.Seek(1, 1) + if err != nil { + log.Println("DEBUG failed to seek:", err) + } + time.Sleep(d) + continue + } + log.Println("WARN Invalid Message received:", err) + time.Sleep(d) + continue } go func(request Request) { var response Response