Skip to content

Commit 4c17aa4

Browse files
committed
BUG: Adds mutex to reloading
1 parent 323dbb1 commit 4c17aa4

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

proxy/ha_proxy.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sort"
88
"strconv"
99
"strings"
10+
"sync"
1011
"text/template"
1112
"time"
1213
)
@@ -23,6 +24,9 @@ var Instance proxy
2324

2425
var reloadPause time.Duration = 1000
2526

27+
var certMu = &sync.Mutex{}
28+
var reloadMu = &sync.Mutex{}
29+
2630
// TODO: Move to data from proxy.go when static (e.g. env. vars.)
2731
type configData struct {
2832
CertsString string
@@ -143,6 +147,8 @@ func (m HaProxy) ReadConfig() (string, error) {
143147

144148
// Reload HAProxy
145149
func (m HaProxy) Reload() error {
150+
reloadMu.Lock()
151+
defer reloadMu.Unlock()
146152
logPrintf("Reloading the proxy")
147153
var reloadErr error
148154
reconfigureAttempts := 20
@@ -332,8 +338,8 @@ func (m *HaProxy) getCertsConfigSnippet() string {
332338
h2 = "h2,"
333339
}
334340
certs = fmt.Sprintf(" ssl crt-list /cfg/crt-list.txt alpn %shttp/1.1", h2)
335-
mu.Lock()
336-
defer mu.Unlock()
341+
certMu.Lock()
342+
defer certMu.Unlock()
337343
writeFile("/cfg/crt-list.txt", []byte(strings.Join(certPaths, "\n")), 0664)
338344
}
339345
if len(os.Getenv("CA_FILE")) > 0 {

proxy/util.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"os/exec"
1313
"regexp"
1414
"strings"
15-
"sync"
1615
"syscall"
1716
"time"
1817
"unicode"
@@ -142,5 +141,3 @@ func replaceNonAlphabetAndNumbers(value []string) string {
142141
reg, _ := regexp.Compile("[^A-Za-z0-9]+")
143142
return reg.ReplaceAllString(strings.Join(value, "_"), "_")
144143
}
145-
146-
var mu = &sync.Mutex{}

0 commit comments

Comments
 (0)