Backport of volumewatcher: prevent panic on nil volume into release/1.3.x #15105
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
This PR is auto-generated from #15101 to be assessed for backporting due to the inclusion of the label backport/1.3.x.
The below text is copied from the body of the original PR.
Fixes #15095
If a GC claim is written and then volume is deleted before the
volumewatcher
enters its run loop, we panic on the nil-pointer access. Simply doing a nil-check at the top of the loop reveals a race condition around shutting down the loop just as a new update is coming in.Have the parent
volumeswatcher
send an initial update on the channel before returning, so that we're still holding the lock. Update the watcher'sStop
method to set the running state, which lets us avoid having a second context and makes stopping synchronous. This reduces the cases we have to handle in the run loop.Updated the tests now that we'll safely return from the goroutine and stop the runner in a larger set of cases. Ran the tests with the
-race
detection flag and fixed up any problems found here as well, and tested this on my localdemocratic-csi
cluster.