Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix data race b/w start and kill #1373

Merged
merged 1 commit into from
Apr 23, 2020
Merged
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
31 changes: 18 additions & 13 deletions child/child.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,14 @@ func (c *Child) start() error {
// down the exit channel.
c.stopLock.RLock()
defer c.stopLock.RUnlock()
if c.stopped {
return
if !c.stopped {
select {
case <-c.stopCh:
case exitCh <- code:
}
}

select {
case <-c.stopCh:
case exitCh <- code:
}
close(exitCh)
}()

c.exitCh = exitCh
Expand Down Expand Up @@ -365,16 +365,13 @@ func (c *Child) reload() error {
return c.signal(c.reloadSignal)
}

// kill sends the signal to kill the process using the configured signal
// if set, else the default system signal
func (c *Child) kill(immediately bool) {
if !c.running() {
return
}

exited := false
process := c.cmd.Process

if c.cmd.ProcessState != nil {
if !c.running() {
log.Printf("[DEBUG] (child) Kill() called but process dead; not waiting for splay.")
return
} else if immediately {
log.Printf("[DEBUG] (child) Kill() called but performing immediate shutdown; not waiting for splay.")
} else {
Expand All @@ -384,6 +381,9 @@ func (c *Child) kill(immediately bool) {
}
}

exited := false
process := c.cmd.Process

if c.killSignal != nil {
if err := process.Signal(c.killSignal); err == nil {
// Wait a few seconds for it to exit
Expand All @@ -410,6 +410,11 @@ func (c *Child) kill(immediately bool) {
}

func (c *Child) running() bool {
select {
case <-c.exitCh:
return false
default:
}
return c.cmd != nil && c.cmd.Process != nil
}

Expand Down