Skip to content

Commit

Permalink
Minor race prevention: do not mutate callers' retry policy
Browse files Browse the repository at this point in the history
Concurrently calling `workflow.WithActivityOptions` with a shared retry policy instance that does not set a backoff coefficient can trigger a race because this function mutated it unnecessarily.
Easy fix: just don't do that :)
  • Loading branch information
Groxx committed Dec 13, 2024
1 parent 2bceb13 commit 6f53817
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -1849,9 +1849,6 @@ func convertRetryPolicy(retryPolicy *RetryPolicy) *s.RetryPolicy {
if retryPolicy == nil {
return nil
}
if retryPolicy.BackoffCoefficient == 0 {
retryPolicy.BackoffCoefficient = backoff.DefaultBackoffCoefficient
}
thriftRetryPolicy := s.RetryPolicy{
InitialIntervalInSeconds: common.Int32Ptr(common.Int32Ceil(retryPolicy.InitialInterval.Seconds())),
MaximumIntervalInSeconds: common.Int32Ptr(common.Int32Ceil(retryPolicy.MaximumInterval.Seconds())),
Expand All @@ -1860,5 +1857,8 @@ func convertRetryPolicy(retryPolicy *RetryPolicy) *s.RetryPolicy {
NonRetriableErrorReasons: retryPolicy.NonRetriableErrorReasons,
ExpirationIntervalInSeconds: common.Int32Ptr(common.Int32Ceil(retryPolicy.ExpirationInterval.Seconds())),
}
if *thriftRetryPolicy.BackoffCoefficient == 0 {
thriftRetryPolicy.BackoffCoefficient = common.Float64Ptr(backoff.DefaultBackoffCoefficient)
}

Check warning on line 1862 in internal/workflow.go

View check run for this annotation

Codecov / codecov/patch

internal/workflow.go#L1861-L1862

Added lines #L1861 - L1862 were not covered by tests
return &thriftRetryPolicy
}

0 comments on commit 6f53817

Please sign in to comment.