aboutsummaryrefslogtreecommitdiff
path: root/weed/util/grace/signal_handling.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2022-09-01 22:34:06 +0500
committerGitHub <noreply@github.com>2022-09-01 10:34:06 -0700
commitc37d6fc01a8b70ea3686a81c2acf9d3da0b5ef09 (patch)
tree42c5205a60b5f37704fa037e50cb61263e868e2e /weed/util/grace/signal_handling.go
parent8c3040db81ac3c3a5b80d675ba3cf044420d4b9a (diff)
downloadseaweedfs-c37d6fc01a8b70ea3686a81c2acf9d3da0b5ef09.tar.xz
seaweedfs-c37d6fc01a8b70ea3686a81c2acf9d3da0b5ef09.zip
avoid data race on grace.hooks (#3572)
https://github.com/seaweedfs/seaweedfs/issues/3564
Diffstat (limited to 'weed/util/grace/signal_handling.go')
-rw-r--r--weed/util/grace/signal_handling.go6
1 files changed, 4 insertions, 2 deletions
diff --git a/weed/util/grace/signal_handling.go b/weed/util/grace/signal_handling.go
index fc7afcad9..24d2b184f 100644
--- a/weed/util/grace/signal_handling.go
+++ b/weed/util/grace/signal_handling.go
@@ -12,7 +12,7 @@ import (
var signalChan chan os.Signal
var hooks = make([]func(), 0)
-var hookLock sync.Mutex
+var hookLock sync.RWMutex
func init() {
signalChan = make(chan os.Signal, 1)
@@ -27,7 +27,9 @@ func init() {
// syscall.SIGQUIT,
)
go func() {
- for _ = range signalChan {
+ hookLock.RLock()
+ defer hookLock.RUnlock()
+ for range signalChan {
for _, hook := range hooks {
hook()
}