Skip to content

Commit 7b4fb53

Browse files
authored
Merge pull request #42 from snorwin/add-read-lock
read lock cmd array
2 parents 5a44b97 + 10d2172 commit 7b4fb53

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
var (
1919
executable string
2020
cmds []*exec.Cmd
21-
l sync.Mutex
21+
l sync.RWMutex
2222
terminated bool
2323
)
2424

@@ -100,13 +100,15 @@ func main() {
100100
terminated = true
101101

102102
// propagate signal to child processes
103+
l.RLock()
103104
for i := range cmds {
104105
if cmds[i].Process != nil {
105106
if err := cmds[i].Process.Signal(sig); err != nil {
106107
log.Warning(fmt.Sprintf("propagating signal %d to process %d failed", sig, cmds[i].Process.Pid))
107108
}
108109
}
109110
}
111+
l.RUnlock()
110112
}
111113
}
112114
}
@@ -131,9 +133,11 @@ func runInstance() {
131133

132134
// launch the actual haproxy including the previous pids to terminate
133135
args := os.Args[1:]
136+
l.RLock()
134137
if len(cmds) > 0 {
135138
args = append(args, []string{"-x", utils.LookupHAProxySocketPath(), "-sf", pids()}...)
136139
}
140+
l.RUnlock()
137141

138142
cmd := exec.Command(executable, args...)
139143
cmd.Stdout = os.Stdout

0 commit comments

Comments
 (0)