Skip to content

Commit 60a6beb

Browse files
dkorunicmjuraga
authored andcommitted
BUG: Fix data race between configureAPI() and reloadConfigurationFile()
ConfigWatcher() issuing reloadConfigurationFile() will data race with ConfigureAPI(), reloadConfigurationFile() doing unsafe write and configureAPI() doing unsafe read. Patch adds global clientMutex for safely handling client changes.
1 parent d321bd8 commit 60a6beb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

configure_data_plane.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ var (
7676
AppLogger *log.Logger
7777
AccLogger *log.Logger
7878
serverStartedCallback func()
79+
clientMutex sync.Mutex
7980
)
8081

8182
func SetServerStartedCallback(callFunc func()) {
@@ -110,6 +111,9 @@ func configureFlags(api *operations.DataPlaneAPI) {
110111
}
111112

112113
func configureAPI(api *operations.DataPlaneAPI) http.Handler {
114+
clientMutex.Lock()
115+
defer clientMutex.Unlock()
116+
113117
cfg := dataplaneapi_config.Get()
114118

115119
haproxyOptions := cfg.HAProxy
@@ -954,6 +958,8 @@ func reloadConfigurationFile(client *client_native.HAProxyClient, haproxyOptions
954958
log.Fatalf(err.Error())
955959
}
956960
log.Info("Rereading Configuration Files")
961+
clientMutex.Lock()
962+
defer clientMutex.Unlock()
957963
client.Configuration = confClient
958964
}
959965

0 commit comments

Comments
 (0)