Skip to content

Commit

Permalink
syncutils.Go context cancellation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
thesaladmander authored and seniorquico committed Oct 14, 2024
1 parent 239949c commit b9a6f3e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/syncutil/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package syncutil

import (
"context"
"errors"
"sync/atomic"

"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -83,7 +84,11 @@ func Go[T any](ctx context.Context, limiter *semaphore.Weighted, fn GoFunc[T], i
defer region.End()
err := fn(egCtx, region, t)
if err != nil {
egErr.CompareAndSwap(nil, err)
if errors.Is(err, context.Canceled) {
egErr.CompareAndSwap(nil, context.Canceled)
} else {
egErr.CompareAndSwap(nil, err)
}
return err
}
return nil
Expand Down

0 comments on commit b9a6f3e

Please sign in to comment.