summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-09-03 16:57:24 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-09-03 16:57:24 -0600
commit82de0f5ad450f3add2a8e7674cf5e019af609a66 (patch)
tree235460147ae873e27113b4f95bf36125d8498e2a
parent0adc8879233bfb020259ebb43e33a35c5b00a8f1 (diff)
The comment at the bottom of hackers_watch.go was wrong; fix the race.
The actual determinant was this race main worker ------------------- Close() Read() Exit() If Read() returned between when Close() happened and when Exit() happened, then the code ran. It doesn't *really* matter if the code runs, but for predictability, set up a wait group to have Close() block until the worker exits.
-rw-r--r--src/nshd/hackers_git/hackers.go8
-rw-r--r--src/nshd/hackers_git/hackers_watch.go6
2 files changed, 8 insertions, 6 deletions
diff --git a/src/nshd/hackers_git/hackers.go b/src/nshd/hackers_git/hackers.go
index b1fffc6..ecbda7a 100644
--- a/src/nshd/hackers_git/hackers.go
+++ b/src/nshd/hackers_git/hackers.go
@@ -23,6 +23,7 @@ type Hackers struct {
util.NullBackend
cfg Config
lock sync.RWMutex
+ workers sync.WaitGroup
users map[int32]user
passwords map[int32]string
@@ -44,11 +45,16 @@ func NewHackers(config Config) *Hackers {
if err != nil {
return nil
}
- go o.worker()
+ o.workers.Add(1)
+ go func() {
+ defer o.workers.Done()
+ o.worker()
+ }()
return &o
}
func (o *Hackers) Close() {
+ defer o.workers.Wait()
logger.Info("Closing hackers.git session")
o.lock.Lock()
defer o.lock.Unlock()
diff --git a/src/nshd/hackers_git/hackers_watch.go b/src/nshd/hackers_git/hackers_watch.go
index 87c856d..9592dab 100644
--- a/src/nshd/hackers_git/hackers_watch.go
+++ b/src/nshd/hackers_git/hackers_watch.go
@@ -181,9 +181,5 @@ func (o *Hackers) worker() {
}
}
}
- // This happens only sometimes--depending on if the main
- // goroutine or this goroutine is killed by os.Exit first;
- // this happens if the main goroutine calls inotify.Close()
- // before this groutine is killed.
- logger.Info("Stopping hackers.git inotify watcher")
+ logger.Info("Stopped hackers.git inotify watcher")
}