Skip to content

pkg/featuregate: add defensive nil check to String() to prevent recovered panic/warning message - #22409

Draft
rrhan0 wants to merge 1 commit into
etcd-io:mainfrom
rrhan0:featuregate-nil-check
Draft

pkg/featuregate: add defensive nil check to String() to prevent recovered panic/warning message#22409
rrhan0 wants to merge 1 commit into
etcd-io:mainfrom
rrhan0:featuregate-nil-check

Conversation

@rrhan0

@rrhan0 rrhan0 commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

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]bool
https://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:

fs.Usage = func() {
fmt.Fprintln(os.Stderr, usageline)
}

Unhappy path call stack:
image

Signed-off-by: Richard Han <47070761+rrhan0@users.noreply.github.com>
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: rrhan0
Once this PR has been reviewed and has the lgtm label, please assign fuweid for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubernetes-prow

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@rrhan0
rrhan0 marked this pull request as draft September 10, 2026 18:33
@rrhan0 rrhan0 changed the title pkg/featuregate: add defensive nil check to String() pkg/featuregate: add defensive nil check to String() to prevent recovered panic/warning message Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant