diff options
author | 2019-02-17 14:57:36 +0000 | |
---|---|---|
committer | 2019-02-17 14:57:36 +0000 | |
commit | a72f3a161c156c13f185df9fb87bf0d20240a49d (patch) | |
tree | 18f8609dcbdba80c31add3ef4fe5a966aa0a1b87 /plugin/reload/setup.go | |
parent | 362d7e96dce051a175e76cff2ce5bd314ad87c28 (diff) | |
download | coredns-a72f3a161c156c13f185df9fb87bf0d20240a49d.tar.gz coredns-a72f3a161c156c13f185df9fb87bf0d20240a49d.tar.zst coredns-a72f3a161c156c13f185df9fb87bf0d20240a49d.zip |
plugin/reload: fix data races (#2567)
Reload didn't take proper care to protect the fields from use in
different goroutines. Add a mutex and add helpers for usage and
interval.
Signed-off-by: Miek Gieben <miek@miek.nl>
Diffstat (limited to 'plugin/reload/setup.go')
-rw-r--r-- | plugin/reload/setup.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/plugin/reload/setup.go b/plugin/reload/setup.go index c6b33e959..ed4d9f85d 100644 --- a/plugin/reload/setup.go +++ b/plugin/reload/setup.go @@ -25,9 +25,10 @@ func init() { // it is used to transmit data between Setup and start of the hook called 'onInstanceStartup' // channel for QUIT is never changed in purpose. // WARNING: this data may be unsync after an invalid attempt of reload Corefile. -var r = reload{interval: defaultInterval, usage: unused, quit: make(chan bool)} -var once sync.Once -var shutOnce sync.Once +var ( + r = reload{dur: defaultInterval, u: unused, quit: make(chan bool)} + once, shutOnce sync.Once +) func setup(c *caddy.Controller) error { c.Next() // 'reload' @@ -69,8 +70,8 @@ func setup(c *caddy.Controller) error { i = i + jitter // prepare info for next onInstanceStartup event - r.interval = i - r.usage = used + r.setInterval(i) + r.setUsage(used) once.Do(func() { caddy.RegisterEventHook("reload", hook) |