diff --git a/opencloud/pkg/backup/provider.go b/opencloud/pkg/backup/provider.go index 1471723785..4355aef825 100644 --- a/opencloud/pkg/backup/provider.go +++ b/opencloud/pkg/backup/provider.go @@ -75,25 +75,20 @@ func (dp *DataProvider) ProduceData() error { wg := sync.WaitGroup{} // crawl spaces - wg.Add(1) - go func() { + wg.Go(func() { for _, d := range dirs { dp.evaluateNodeDir(d) } - wg.Done() - }() + }) // crawl trash - wg.Add(1) - go func() { + wg.Go(func() { dp.evaluateTrashDir() - wg.Done() - }() + }) // crawl blobstore if !dp.skipBlobs { - wg.Add(1) - go func() { + wg.Go(func() { bs, err := dp.lbs.List() if err != nil { fmt.Println("error listing blobs", err) @@ -102,8 +97,7 @@ func (dp *DataProvider) ProduceData() error { for _, bn := range bs { dp.Events <- BlobData{BlobPath: dp.lbs.Path(bn)} } - wg.Done() - }() + }) } // wait for all crawlers to finish diff --git a/opencloud/pkg/revisions/revisions.go b/opencloud/pkg/revisions/revisions.go index f5c477e5c0..5f81c92175 100644 --- a/opencloud/pkg/revisions/revisions.go +++ b/opencloud/pkg/revisions/revisions.go @@ -227,13 +227,11 @@ func listFolder(path string, ch chan<- string, workers chan struct{}) error { for _, child := range children { if child.IsDir() { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { if err := listFolder(filepath.Join(path, child.Name()), ch, workers); err != nil { fmt.Println("error listing", path, err) } - }() + }) } if _versionRegex.MatchString(child.Name()) { diff --git a/opencloud/pkg/runtime/service/service.go b/opencloud/pkg/runtime/service/service.go index c83fdf78da..7fcef40076 100644 --- a/opencloud/pkg/runtime/service/service.go +++ b/opencloud/pkg/runtime/service/service.go @@ -526,9 +526,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) error { s.Log.Info().Msg("starting graceful shutdown") start := time.Now() wg := sync.WaitGroup{} - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { ctx, cancel := context.WithTimeout(context.Background(), _defaultShutdownTimeoutDuration) defer cancel() s.Log.Debug().Msg("starting runtime listener shutdown") @@ -537,7 +535,7 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) error { return } s.Log.Debug().Msg("runtime listener shutdown done") - }() + }) // shutdown services in the order defined in the config // any services not listed will be shutdown in parallel afterwards diff --git a/services/antivirus/pkg/service/service.go b/services/antivirus/pkg/service/service.go index 796cf54c60..840c28520d 100644 --- a/services/antivirus/pkg/service/service.go +++ b/services/antivirus/pkg/service/service.go @@ -139,9 +139,7 @@ func (av Antivirus) Run() error { wg := sync.WaitGroup{} for range av.config.Workers { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { EventLoop: for { @@ -170,7 +168,7 @@ func (av Antivirus) Run() error { break EventLoop } } - }() + }) } wg.Wait() diff --git a/services/frontend/pkg/command/events.go b/services/frontend/pkg/command/events.go index 24f618d8f1..be899194c2 100644 --- a/services/frontend/pkg/command/events.go +++ b/services/frontend/pkg/command/events.go @@ -146,9 +146,7 @@ func AutoAcceptShares(ev events.ShareCreated, autoAcceptDefault bool, l log.Logg wg := sync.WaitGroup{} for i := 0; i < maxConcurrency; i++ { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { for userID := range work { if !autoAcceptShares(ctx, userID, autoAcceptDefault, vs) { @@ -179,7 +177,7 @@ func AutoAcceptShares(ev events.ShareCreated, autoAcceptDefault bool, l log.Logg }().Interface("status", resp.GetStatus()).Str("userid", userID.GetOpaqueId()).Msg("unexpected status code while accepting share") } } - }() + }) } // Wait for all goroutines to finish diff --git a/services/notifications/pkg/service/service.go b/services/notifications/pkg/service/service.go index 0f27191bd3..96d03cb2c0 100644 --- a/services/notifications/pkg/service/service.go +++ b/services/notifications/pkg/service/service.go @@ -114,9 +114,7 @@ EventLoop: break EventLoop } // TODO: needs to be replaced with a worker pool - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { switch e := evt.Event.(type) { case events.SpaceShared: @@ -134,7 +132,7 @@ EventLoop: case events.SendEmailsEvent: s.sendGroupedEmailsJob(e, evt.ID) } - }() + }) if s.stopped.Load() { break EventLoop diff --git a/services/postprocessing/pkg/service/service.go b/services/postprocessing/pkg/service/service.go index 09d742d119..ea6f9f08fa 100644 --- a/services/postprocessing/pkg/service/service.go +++ b/services/postprocessing/pkg/service/service.go @@ -109,9 +109,7 @@ func (pps *PostprocessingService) Run() error { wg := sync.WaitGroup{} for range pps.c.Workers { - wg.Add(1) - go func() { - defer wg.Done() + wg.Go(func() { EventLoop: for { @@ -149,7 +147,7 @@ func (pps *PostprocessingService) Run() error { } } } - }() + }) } wg.Wait()