Browse Source

lib/watchaggregator: Properly unsubscribe from events when stopping (ref #5372) (#5374)

Jakob Borg 6 years ago
parent
commit
fc860df514
1 changed files with 4 additions and 2 deletions
  1. 4 2
      lib/watchaggregator/aggregator.go

+ 4 - 2
lib/watchaggregator/aggregator.go

@@ -136,10 +136,13 @@ func (a *aggregator) mainLoop(in <-chan fs.Event, out chan<- []string, cfg *conf
 	a.notifyTimer = time.NewTimer(a.notifyDelay)
 	a.notifyTimer = time.NewTimer(a.notifyDelay)
 	defer a.notifyTimer.Stop()
 	defer a.notifyTimer.Stop()
 
 
-	inProgress := make(map[string]struct{})
 	inProgressItemSubscription := events.Default.Subscribe(events.ItemStarted | events.ItemFinished)
 	inProgressItemSubscription := events.Default.Subscribe(events.ItemStarted | events.ItemFinished)
+	defer events.Default.Unsubscribe(inProgressItemSubscription)
 
 
 	cfg.Subscribe(a)
 	cfg.Subscribe(a)
+	defer cfg.Unsubscribe(a)
+
+	inProgress := make(map[string]struct{})
 
 
 	for {
 	for {
 		select {
 		select {
@@ -154,7 +157,6 @@ func (a *aggregator) mainLoop(in <-chan fs.Event, out chan<- []string, cfg *conf
 		case folderCfg := <-a.folderCfgUpdate:
 		case folderCfg := <-a.folderCfgUpdate:
 			a.updateConfig(folderCfg)
 			a.updateConfig(folderCfg)
 		case <-a.ctx.Done():
 		case <-a.ctx.Done():
-			cfg.Unsubscribe(a)
 			l.Debugln(a, "Stopped")
 			l.Debugln(a, "Stopped")
 			return
 			return
 		}
 		}