[release/1.7] Fix panic in NRI from nil CRI reference #10406
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Backport of #10401)
A nil CRIImplementation field can cause a nil pointer dereference and panic during startup recovery.
Prior to this change, the nri.API struct would have a nil cri (CRIImplementation) field after nri.NewAPI until nri.Register was called. Register is called mid-way through initialization of the CRI plugin, but recovery for containers occurs prior to that. Container recovery includes establishing new exit monitors for existing containers that were discovered. When a container exits, NRI plugins are given the opportunity to be notified about the lifecycle event, and this is done by accessing that CRIImplementation field inside the nri.API. If a container exits prior to nri.Register being called, access to the CRIImplementation field can cause a panic.
Here's the call-path:
recover()
to recover state from previous runs of containerdrecover()
then attempts to recover all containers throughloadContainer()
loadContainer()
finds a container that is still running, it waits for the task (internal containerd object) to exit and sets up exit monitoringnri.WithContainerExit
to notify any subscribed NRI pluginscri
implementation member field in thenri.API
struct is set as part of theRegister()
methodnri.Register()
method is only called much further down in the CRIRun()
method(manually backported from commit 10aec35)