Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions child.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a backward compatible change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably fine and we can have a minor version bump for this. Caller won't fail but would need to fix lint error if it has linter.

return c.proc.Signal(os.Kill)
}

func (c *child) waitExit(result chan<- error, exited chan<- struct{}) {
Expand Down
7 changes: 6 additions & 1 deletion child_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
15 changes: 7 additions & 8 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
2 changes: 1 addition & 1 deletion http_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ func Example_httpShutdown() {
})

// Wait for connections to drain.
server.Shutdown(context.Background())
_ = server.Shutdown(context.Background())
}
4 changes: 2 additions & 2 deletions tcp_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}()
}
Expand Down
2 changes: 1 addition & 1 deletion testing/http_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ func Example_httpShutdown() {
})

// Wait for connections to drain.
server.Shutdown(context.Background())
_ = server.Shutdown(context.Background())
}
8 changes: 6 additions & 2 deletions upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion upgrader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down