From d008198a3880c329c3251ad2287dcc345437547a Mon Sep 17 00:00:00 2001 From: Lucas Bremgartner Date: Mon, 20 Apr 2020 10:53:44 +0200 Subject: [PATCH] Fix concurrency problem in afterFind Fixes: gobuffalo/pop#530 --- callbacks.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/callbacks.go b/callbacks.go index b841df642..19785e89f 100644 --- a/callbacks.go +++ b/callbacks.go @@ -2,8 +2,6 @@ package pop import ( "reflect" - - "golang.org/x/sync/errgroup" ) // AfterFindable callback will be called after a record, or records, @@ -28,21 +26,18 @@ func (m *Model) afterFind(c *Connection) error { return nil } - wg := &errgroup.Group{} for i := 0; i < rv.Len(); i++ { - func(i int) { - wg.Go(func() error { - y := rv.Index(i) - y = y.Addr() - if x, ok := y.Interface().(AfterFindable); ok { - return x.AfterFind(c) - } - return nil - }) - }(i) + y := rv.Index(i) + y = y.Addr() + x, ok := y.Interface().(AfterFindable) + if !ok { + continue + } + if err := x.AfterFind(c); err != nil { + return err + } } - - return wg.Wait() + return nil } // BeforeSaveable callback will be called before a record is