From 1157d38c6f918dcc816837649b7742a4ee70e76d Mon Sep 17 00:00:00 2001 From: Brad Moylan Date: Tue, 9 Apr 2019 03:53:17 -0700 Subject: [PATCH] [fix] Trim whitespace from pidfile content (#84) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Before this PR We saw the below error in production: ``` failed to determine service status: failed to determine running processes: pid file did not contain an integer: strconv.Atoi: parsing "12773\n": invalid syntax ``` From reading the `Start` code I'm not sure how the newline got in there, but this should protect us from it in the future. ## After this PR We will ignore spurious whitespace in the pidfile --- This change is [Reviewable](https://reviewable.io/reviews/palantir/go-java-launcher/84) --- init/cli/lib.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/init/cli/lib.go b/init/cli/lib.go index 7aaac034..18af93ae 100644 --- a/init/cli/lib.go +++ b/init/cli/lib.go @@ -21,6 +21,7 @@ import ( "os/exec" "path/filepath" "strconv" + "strings" "syscall" "github.com/palantir/pkg/cli" @@ -102,7 +103,7 @@ func getCmdProcess(name string) (*int, *os.Process, error) { return nil, nil, errors.Wrap(err, "failed to read pidfile") } - pid, err := strconv.Atoi(string(pidBytes)) + pid, err := strconv.Atoi(strings.TrimSpace(string(pidBytes))) if err != nil { return nil, nil, errors.Wrap(err, "pid file did not contain an integer") }