Skip to content

Commit

Permalink
fix: parsing pidfile with newlines
Browse files Browse the repository at this point in the history
Fix parsing pid files that may contain newlines

It's seen that very rarely the pid file might be created with a newline
and then that would cause the process to restart continuously since we
fail to parse the pid into an integer. Fix by trimming of newlines.

Signed-off-by: Noel Georgi <[email protected]>
  • Loading branch information
frezbo committed Jul 19, 2022
1 parent 14946ee commit 6c412b0
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"errors"
"io/ioutil"
"log"
Expand Down Expand Up @@ -70,6 +71,8 @@ func getProcessId() (int, error) {
if err != nil {
return 0, err
}
// remove any newlines
pidData = bytes.TrimRight(pidData, "\n")
pid, err := strconv.Atoi(string(pidData))
if err != nil {
return 0, err
Expand Down

0 comments on commit 6c412b0

Please sign in to comment.