Skip to content

Commit

Permalink
serviceconfig: Return errors instead of skipping invalid retry policy…
Browse files Browse the repository at this point in the history
… config (#7905)
  • Loading branch information
dfawley authored Dec 5, 2024
1 parent 645aadf commit f53724d
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 58 deletions.
17 changes: 10 additions & 7 deletions service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,18 +268,21 @@ func parseServiceConfig(js string, maxAttempts int) *serviceconfig.ParseResult {
return &serviceconfig.ParseResult{Config: &sc}
}

func isValidRetryPolicy(jrp *jsonRetryPolicy) bool {
return jrp.MaxAttempts > 1 &&
jrp.InitialBackoff > 0 &&
jrp.MaxBackoff > 0 &&
jrp.BackoffMultiplier > 0 &&
len(jrp.RetryableStatusCodes) > 0
}

func convertRetryPolicy(jrp *jsonRetryPolicy, maxAttempts int) (p *internalserviceconfig.RetryPolicy, err error) {
if jrp == nil {
return nil, nil
}

if jrp.MaxAttempts <= 1 ||
jrp.InitialBackoff <= 0 ||
jrp.MaxBackoff <= 0 ||
jrp.BackoffMultiplier <= 0 ||
len(jrp.RetryableStatusCodes) == 0 {
logger.Warningf("grpc: ignoring retry policy %v due to illegal configuration", jrp)
return nil, nil
if !isValidRetryPolicy(jrp) {
return nil, fmt.Errorf("invalid retry policy (%+v): ", jrp)
}

if jrp.MaxAttempts < maxAttempts {
Expand Down
Loading

0 comments on commit f53724d

Please sign in to comment.