Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fix so plugin will get unloaded and tasks disabled after plugin killed
Browse files Browse the repository at this point in the history
  • Loading branch information
kjlyon committed Jul 18, 2017
1 parent 359a98b commit df23ca1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
7 changes: 0 additions & 7 deletions control/available_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,6 @@ func (a *availablePlugin) Kill(r string) error {
// CheckHealth checks the health of a plugin and updates
// a.failedHealthChecks
func (a *availablePlugin) CheckHealth() {
if a.IsRemote() {
runnerLog.WithFields(log.Fields{
"_module": "control-aplugin",
"_block": "check-health",
}).Debug(fmt.Sprintf("bypassing check-health on standalone plugin"))
return
}
go func() {
a.healthChan <- a.client.Ping()
}()
Expand Down
4 changes: 4 additions & 0 deletions control/plugin/client/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ func (g *grpcClient) handleInStream(
for {
in, err := g.stream.Recv()
if err != nil {
g.conn.Close()
if strings.Contains(err.Error(), "transport is closing") {
errChan <- errors.New("connection broken")
}
errChan <- err
break
}
Expand Down
25 changes: 24 additions & 1 deletion control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,9 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter
}

colClient := ap.client.(client.PluginCollectorClient)
defer ap.client.(client.PluginCollectorClient).Close()
if !ap.isRemote {
defer ap.client.(client.PluginCollectorClient).Close()
}

cfg := plugin.ConfigType{
ConfigDataNode: cfgNode,
Expand Down Expand Up @@ -653,6 +655,27 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter
}).Error("load plugin error while adding loaded plugin to load plugins collection")
resultChan <- result{nil, aErr}
}
if ap.isRemote && aErr == nil {
// monitor standalone plugins. Unload them from the plugin catalog and metrics list
// when we detect they are no longer online.
go func() {
defer ap.client.(client.PluginCollectorClient).Close()
for {
time.Sleep(5 * time.Second)
go ap.CheckHealth()
if ap.failedHealthChecks > 3 {
p.UnloadPlugin(lPlugin)
return
}
if _, err := p.loadedPlugins.get(lPlugin.Key()); err != nil {
// prevent leaking routine when plugin is unloaded normally
return
}

}
}()

}
resultChan <- result{lPlugin, nil}
return
}()
Expand Down

0 comments on commit df23ca1

Please sign in to comment.