summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGahl Saraf <gahl@raftt.io>2021-12-22 21:16:21 +0200
committerGitHub <noreply@github.com>2021-12-22 20:16:21 +0100
commitcc39341eb9b6408091e7ede9cdcfc757b18f6398 (patch)
tree966269d37f75812bf6f0754e803c974b94399bba
parentbf7f82f7b255c80cfb0bf93110b361657ec02f3b (diff)
lib: Fix panic due to closed event subscriptions on shutdown (#8079)
-rw-r--r--lib/model/folder_summary.go6
-rw-r--r--lib/syncthing/auditservice.go6
-rw-r--r--lib/syncthing/verboseservice.go6
-rw-r--r--lib/watchaggregator/aggregator.go6
4 files changed, 19 insertions, 5 deletions
diff --git a/lib/model/folder_summary.go b/lib/model/folder_summary.go
index c9d229b50b..58427b3183 100644
--- a/lib/model/folder_summary.go
+++ b/lib/model/folder_summary.go
@@ -178,7 +178,11 @@ func (c *folderSummaryService) listenForUpdates(ctx context.Context) error {
// This loop needs to be fast so we don't miss too many events.
select {
- case ev := <-sub.C():
+ case ev, ok := <-sub.C():
+ if !ok {
+ <-ctx.Done()
+ return ctx.Err()
+ }
c.processUpdate(ev)
case <-ctx.Done():
return ctx.Err()
diff --git a/lib/syncthing/auditservice.go b/lib/syncthing/auditservice.go
index c56dbaf4e8..273333be0d 100644
--- a/lib/syncthing/auditservice.go
+++ b/lib/syncthing/auditservice.go
@@ -38,7 +38,11 @@ func (s *auditService) Serve(ctx context.Context) error {
for {
select {
- case ev := <-sub.C():
+ case ev, ok := <-sub.C():
+ if !ok {
+ <-ctx.Done()
+ return ctx.Err()
+ }
enc.Encode(ev)
case <-ctx.Done():
return ctx.Err()
diff --git a/lib/syncthing/verboseservice.go b/lib/syncthing/verboseservice.go
index 7bcb196b79..b23027df31 100644
--- a/lib/syncthing/verboseservice.go
+++ b/lib/syncthing/verboseservice.go
@@ -31,7 +31,11 @@ func (s *verboseService) Serve(ctx context.Context) error {
defer sub.Unsubscribe()
for {
select {
- case ev := <-sub.C():
+ case ev, ok := <-sub.C():
+ if !ok {
+ <-ctx.Done()
+ return ctx.Err()
+ }
formatted := s.formatEvent(ev)
if formatted != "" {
l.Verboseln(formatted)
diff --git a/lib/watchaggregator/aggregator.go b/lib/watchaggregator/aggregator.go
index 5c176fde8c..322aa502e4 100644
--- a/lib/watchaggregator/aggregator.go
+++ b/lib/watchaggregator/aggregator.go
@@ -162,8 +162,10 @@ func (a *aggregator) mainLoop(in <-chan fs.Event, out chan<- []string, cfg confi
select {
case event := <-in:
a.newEvent(event, inProgress)
- case event := <-inProgressItemSubscription.C():
- updateInProgressSet(event, inProgress)
+ case event, ok := <-inProgressItemSubscription.C():
+ if ok {
+ updateInProgressSet(event, inProgress)
+ }
case <-a.notifyTimer.C:
a.actOnTimer(out)
case interval := <-a.notifyTimerResetChan: