-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Panic from dynamicRESTMapper when using lazy initialization #1712
Comments
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
When
dynamicRESTMapper
lazy initialization fails, any subsequent calls to it will panic (runtime error: invalid memory address or nil pointer dereference
) becausestaticMapper
is uninitialized.I ran into this when my cluster could not be reached, so I'll illustrate the problem this way, but any error returned by
setStaticMapper
duringinit
will result in the same issue.How to reproduce
Suggested fix
sync.Once
is not suitable for guarding the lazy initialization code because the initialization should be retried until successful, not just tried once. I couldn't find an existing solution, so I propose to create a custom version ofsync.Once
that is done only when the function given toDo
returns withtrue
, although, other alternative implementations might be fine too.This should be used instead of
sync.Once
, updating the inline function passed toDo
with areturn err == nil
statement.The text was updated successfully, but these errors were encountered: