csi: avoid a nil pointer when handling plugin events (#15518)

If a plugin crashes quickly enough, we can get into a situation where the
deregister function is called before it's ever registered. Safely handle the
resulting nil pointer in the dynamic registry by not emitting a plugin event,
but also update the plugin event handler to tolerate nil pointers in case we
wire it up elsewhere in the future.
This commit is contained in:
Tim Gross 2022-12-12 08:42:57 -05:00 committed by GitHub
parent be3f89b5f9
commit 989d7d9fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions

3
.changelog/15518.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
csi: Fixed a bug where a crashing plugin could panic the Nomad client
```

View File

@ -269,12 +269,14 @@ func (d *dynamicRegistry) DeregisterPlugin(ptype, name, allocID string) error {
}
}
if info != nil {
broadcaster := d.broadcasterForPluginType(ptype)
event := &PluginUpdateEvent{
EventType: EventTypeDeregistered,
Info: info,
}
broadcaster.broadcast(event)
}
return d.sync()
}

View File

@ -149,7 +149,7 @@ func (c *csiManager) resyncPluginsFromRegistry(ptype string) {
// handlePluginEvent syncs a single event against the plugin registry
func (c *csiManager) handlePluginEvent(event *dynamicplugins.PluginUpdateEvent) {
if event == nil {
if event == nil || event.Info == nil {
return
}
c.logger.Trace("dynamic plugin event",