open-nomad/nomad/volumewatcher
Tim Gross 4d7a4171cd
volumewatcher: prevent panic on nil volume (#15101)
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's `Stop`
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.
2022-11-01 16:53:10 -04:00
..
interfaces.go csi: update volumewatcher to use unpublish RPC (#8579) 2020-08-06 14:31:18 -04:00
interfaces_test.go csi: fix mocked modes in volumewatcher test (#12104) 2022-02-23 09:51:20 -05:00
volume_watcher.go volumewatcher: prevent panic on nil volume (#15101) 2022-11-01 16:53:10 -04:00
volume_watcher_test.go ci: swap ci parallelization for unconstrained gomaxprocs 2022-03-15 12:58:52 -05:00
volumes_watcher.go volumewatcher: prevent panic on nil volume (#15101) 2022-11-01 16:53:10 -04:00
volumes_watcher_test.go volumewatcher: prevent panic on nil volume (#15101) 2022-11-01 16:53:10 -04:00