Skip to content

Commit

Permalink
csi: avoid a nil pointer when handling plugin events (#15518)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tgross committed Dec 12, 2022
1 parent 493389e commit 837f9e2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/15518.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
csi: Fixed a bug where a crashing plugin could panic the Nomad client
```
12 changes: 7 additions & 5 deletions client/dynamicplugins/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,14 @@ func (d *dynamicRegistry) DeregisterPlugin(ptype, name, allocID string) error {
}
}

broadcaster := d.broadcasterForPluginType(ptype)
event := &PluginUpdateEvent{
EventType: EventTypeDeregistered,
Info: info,
if info != nil {
broadcaster := d.broadcasterForPluginType(ptype)
event := &PluginUpdateEvent{
EventType: EventTypeDeregistered,
Info: info,
}
broadcaster.broadcast(event)
}
broadcaster.broadcast(event)

return d.sync()
}
Expand Down
2 changes: 1 addition & 1 deletion client/pluginmanager/csimanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 837f9e2

Please sign in to comment.