Skip to content

Commit

Permalink
errgroup: return context.Canceled instead of using another context (#…
Browse files Browse the repository at this point in the history
…1410)

errgroup seems to prefer the error raised by one of its goroutines
rather than the calling context's cancelation for Wait's return value,
return context.Canceled to set Wait result & cancel pull
  • Loading branch information
serprex authored Feb 29, 2024
1 parent e34bc06 commit ff1589e
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,7 @@ func (a *FlowableActivity) replicateQRepPartition(ctx context.Context,
var rowsSynced int
bufferSize := shared.FetchAndChannelSize
if config.SourcePeer.Type == protos.DBType_POSTGRES {
taskCtx, taskCancel := context.WithCancel(ctx)
errGroup, errCtx := errgroup.WithContext(taskCtx)
errGroup, errCtx := errgroup.WithContext(ctx)
stream := model.NewQRecordStream(bufferSize)
errGroup.Go(func() error {
pgConn := srcConn.(*connpostgres.PostgresConnector)
Expand All @@ -666,8 +665,7 @@ func (a *FlowableActivity) replicateQRepPartition(ctx context.Context,
a.Alerter.LogFlowError(ctx, config.FlowJobName, err)
return fmt.Errorf("failed to sync records: %w", err)
}
taskCancel()
return nil
return context.Canceled
})

err = errGroup.Wait()
Expand Down

0 comments on commit ff1589e

Please sign in to comment.