diff --git a/child.go b/child.go index 1b5e04d..cd71d1f 100644 --- a/child.go +++ b/child.go @@ -82,8 +82,8 @@ func (c *child) String() string { return c.proc.String() } -func (c *child) Kill() { - c.proc.Signal(os.Kill) +func (c *child) Kill() error { + return c.proc.Signal(os.Kill) } func (c *child) waitExit(result chan<- error, exited chan<- struct{}) { diff --git a/child_test.go b/child_test.go index bd32804..2e2f9d2 100644 --- a/child_test.go +++ b/child_test.go @@ -30,7 +30,12 @@ func TestChildKill(t *testing.T) { proc := <-procs - go child.Kill() + go func() { + if err := child.Kill(); err != nil { + t.Errorf("Failed to kill child: %s", err) + } + }() + if sig := proc.recvSignal(nil); sig != os.Kill { t.Errorf("Received %v instead of os.Kill", sig) } diff --git a/doc.go b/doc.go index cc68c13..0e5f6c2 100644 --- a/doc.go +++ b/doc.go @@ -13,18 +13,18 @@ // To use this library with systemd you need to use the PIDFile option in the service // file. // -// [Unit] -// Description=Service using tableflip +// [Unit] +// Description=Service using tableflip // -// [Service] -// ExecStart=/path/to/binary -some-flag /path/to/pid-file -// ExecReload=/bin/kill -HUP $MAINPID -// PIDFile=/path/to/pid-file +// [Service] +// ExecStart=/path/to/binary -some-flag /path/to/pid-file +// ExecReload=/bin/kill -HUP $MAINPID +// PIDFile=/path/to/pid-file // // Then pass /path/to/pid-file to New. You can use systemd-run to // test your implementation: // -// systemd-run --user -p PIDFile=/path/to/pid-file /path/to/binary +// systemd-run --user -p PIDFile=/path/to/pid-file /path/to/binary // // systemd-run will print a unit name, which you can use with systemctl to // inspect the service. @@ -44,5 +44,4 @@ // which may be necessary in certain development circumstances, but it will not // provide zero downtime upgrades when running on Windows. See the `testing` // package for an example of how to use it. -// package tableflip diff --git a/go.mod b/go.mod index 7c90929..3aa627f 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/cloudflare/tableflip go 1.14 -require golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 +require golang.org/x/sys v0.1.0 diff --git a/go.sum b/go.sum index 9b4cc1b..b69ea85 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/http_example_test.go b/http_example_test.go index 1180045..6a3b8c8 100644 --- a/http_example_test.go +++ b/http_example_test.go @@ -77,5 +77,5 @@ func Example_httpShutdown() { }) // Wait for connections to drain. - server.Shutdown(context.Background()) + _ = server.Shutdown(context.Background()) } diff --git a/tcp_example_test.go b/tcp_example_test.go index 969bbe2..c4ec273 100644 --- a/tcp_example_test.go +++ b/tcp_example_test.go @@ -60,8 +60,8 @@ func Example_tcpServer() { } go func() { - c.SetDeadline(time.Now().Add(time.Second)) - c.Write([]byte("It is a mistake to think you can solve any major problems just with potatoes.\n")) + _ = c.SetDeadline(time.Now().Add(time.Second)) + _, _ = c.Write([]byte("It is a mistake to think you can solve any major problems just with potatoes.\n")) c.Close() }() } diff --git a/testing/http_example_test.go b/testing/http_example_test.go index ea8b190..a89c944 100644 --- a/testing/http_example_test.go +++ b/testing/http_example_test.go @@ -94,5 +94,5 @@ func Example_httpShutdown() { }) // Wait for connections to drain. - server.Shutdown(context.Background()) + _ = server.Shutdown(context.Background()) } diff --git a/upgrader.go b/upgrader.go index 59e0afe..9b5d5d6 100644 --- a/upgrader.go +++ b/upgrader.go @@ -263,11 +263,15 @@ func (u *Upgrader) doUpgrade() (*os.File, error) { return nil, fmt.Errorf("child %s exited: %s", child, err) case <-u.stopC: - child.Kill() + if err = child.Kill(); err != nil { + return nil, fmt.Errorf("terminating child: %w", err) + } return nil, errors.New("terminating") case <-readyTimeout: - child.Kill() + if err = child.Kill(); err != nil { + return nil, fmt.Errorf("terminating child: %w", err) + } return nil, fmt.Errorf("new child %s timed out", child) case file := <-child.ready: diff --git a/upgrader_test.go b/upgrader_test.go index dc724f7..acb21d3 100644 --- a/upgrader_test.go +++ b/upgrader_test.go @@ -137,7 +137,7 @@ func childProcess(upg *Upgrader) error { // error here won't make the parent fail, so don't bother. if rExit != nil { var b [1]byte - rExit.Read(b[:]) + _, _ = rExit.Read(b[:]) } return nil