Skip to content

Commit 1f4cae8

Browse files
committed
��runningServersForked should be read with runningServerReg held
The current code in `fork()` is racy in the sense that two concurrent go routines might call fork() at the same time, see that �runningServersForked is false and perform two forks. Holding runningServerReg makes sure that only one of the goroutines will see runningServersForked set to false.
1 parent 2973141 commit 1f4cae8

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

endless.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,13 @@ func (srv *endlessServer) hammerTime(d time.Duration) {
416416
}
417417

418418
func (srv *endlessServer) fork() (err error) {
419+
runningServerReg.Lock()
420+
defer runningServerReg.Unlock()
421+
419422
// only one server isntance should fork!
420423
if runningServersForked {
421424
return errors.New("Another process already forked. Ignoring this one.")
422425
}
423-
runningServerReg.Lock()
424-
defer runningServerReg.Unlock()
425426

426427
runningServersForked = true
427428

0 commit comments

Comments
 (0)