pkg/featuregate: add defensive nil check to String() to prevent recovered panic/warning message - #22409
pkg/featuregate: add defensive nil check to String() to prevent recovered panic/warning message#22409rrhan0 wants to merge 1 commit into
Conversation
Signed-off-by: Richard Han <47070761+rrhan0@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: rrhan0 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @rrhan0. Thanks for your PR. I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
AI Disclosure:
Copilot was used to find the origin of the panic
This PR adds a nil check to featureGate.String() to prevent panic (recovered) messages printed by flag.go in the standard library. The code path that causes the panic message appears to not be in use (it was overridden), but the default usage function of flag and presumably PrintDefaults() will trigger the panic message. It happens because flag in the standard library seems to call the String() method on an uninitialized featureGate.
I discovered this when looking for inconsistencies between the --help text in help.go and the usage descriptions in the cli flag parser. I will create another issue for the --help text inconsistencies/outdated.
Panic message and cause:
panic calling String method on zero featuregate.featureGate for flag feature-gates: interface conversion: interface {} is nil, not map[featuregate.Feature]boolhttps://github.com/golang/go/blob/b35e1f9be31698bd1aa71322cc50208a7161c9cb/src/flag/flag.go#L573-L582
Overriden usage function, if you comment this out, the unhappy path will happen:
etcd/server/etcdmain/config.go
Lines 93 to 95 in 6799d48
Unhappy path call stack:
