Browse Source

avoid data race on grace.hooks (#3572)

https://github.com/seaweedfs/seaweedfs/issues/3564
pull/3579/head
Konstantin Lebedev 2 years ago
committed by GitHub
parent
commit
c37d6fc01a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      weed/util/grace/signal_handling.go

6
weed/util/grace/signal_handling.go

@ -12,7 +12,7 @@ import (
var signalChan chan os.Signal var signalChan chan os.Signal
var hooks = make([]func(), 0) var hooks = make([]func(), 0)
var hookLock sync.Mutex
var hookLock sync.RWMutex
func init() { func init() {
signalChan = make(chan os.Signal, 1) signalChan = make(chan os.Signal, 1)
@ -27,7 +27,9 @@ func init() {
// syscall.SIGQUIT, // syscall.SIGQUIT,
) )
go func() { go func() {
for _ = range signalChan {
hookLock.RLock()
defer hookLock.RUnlock()
for range signalChan {
for _, hook := range hooks { for _, hook := range hooks {
hook() hook()
} }

Loading…
Cancel
Save