-
Notifications
You must be signed in to change notification settings - Fork 4.6k
pickfirst: guard config parsing on GRPC_EXPERIMENTAL_PICKFIRST_LB_CONFIG #6470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
pickfirst.go
Outdated
| } | ||
|
|
||
| if envconfig.PickFirstLBConfig && b.cfg != nil && b.cfg.ShuffleAddressList { | ||
| if cfg != nil && cfg.ShuffleAddressList { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make cfg a value instead, to avoid the need for nil checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change ParseConfig to return a value instead of pointer, and switched to value here.
pickfirst.go
Outdated
| var cfg *pfConfig | ||
| if state.BalancerConfig != nil { | ||
| cfg, ok := state.BalancerConfig.(*pfConfig) | ||
| var ok bool | ||
| cfg, ok = state.BalancerConfig.(*pfConfig) | ||
| if !ok { | ||
| return fmt.Errorf("pickfirstBalancer: received nil or illegal BalancerConfig (type %T): %v", state.BalancerConfig, state.BalancerConfig) | ||
| } | ||
| b.cfg = cfg | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose if you wanted to simplify this (optional):
cfg, ok := state.BalancerConfig.(*pfConfig)
if state.BalancerConfig != nil && !ok {
return fmt.Errorf("illegal config")
}And that (existing) "nil" in the error message is wrong, isn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, for both. Thanks.
- use a config value instead of pointer - simplify the LB config type assertion check - fix the error message to not include `nil`
Fixes #6469.
RELEASE NOTES: