فهرست منبع

fix(portable): need to close process when deleting plugin (#1414)

Signed-off-by: Jiyong Huang <huangjy@emqx.io>

Signed-off-by: Jiyong Huang <huangjy@emqx.io>
ngjaying 2 سال پیش
والد
کامیت
15b86614f3
2فایلهای تغییر یافته به همراه21 افزوده شده و 10 حذف شده
  1. 6 1
      internal/plugin/portable/manager.go
  2. 15 9
      internal/plugin/portable/runtime/plugin_ins_manager.go

+ 6 - 1
internal/plugin/portable/manager.go

@@ -1,4 +1,4 @@
-// Copyright 2021 EMQ Technologies Co., Ltd.
+// Copyright 2021-2022 EMQ Technologies Co., Ltd.
 //
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // you may not use this file except in compliance with the License.
@@ -345,6 +345,11 @@ func (m *Manager) Delete(name string) error {
 	if !ok {
 	if !ok {
 		return fmt.Errorf("portable plugin %s is not found", name)
 		return fmt.Errorf("portable plugin %s is not found", name)
 	}
 	}
+	pm := runtime.GetPluginInsManager()
+	err := pm.Kill(name)
+	if err != nil {
+		conf.Log.Errorf("fail to kill portable plugin %s process, please try to kill it manually", name)
+	}
 	// unregister the plugin
 	// unregister the plugin
 	m.reg.Delete(name)
 	m.reg.Delete(name)
 	// delete files and uninstall metas
 	// delete files and uninstall metas

+ 15 - 9
internal/plugin/portable/runtime/plugin_ins_manager.go

@@ -178,16 +178,22 @@ func (p *pluginInsManager) getOrStartProcess(pluginMeta *PluginMeta, pconf *Port
 		return nil, fmt.Errorf("invalid conf: %v", pconf)
 		return nil, fmt.Errorf("invalid conf: %v", pconf)
 	}
 	}
 	var cmd *exec.Cmd
 	var cmd *exec.Cmd
-	switch pluginMeta.Language {
-	case "go":
-		conf.Log.Printf("starting go plugin executable %s", pluginMeta.Executable)
-		cmd = exec.Command(pluginMeta.Executable, string(jsonArg))
+	err = infra.SafeRun(func() error {
+		switch pluginMeta.Language {
+		case "go":
+			conf.Log.Printf("starting go plugin executable %s", pluginMeta.Executable)
+			cmd = exec.Command(pluginMeta.Executable, string(jsonArg))
 
 
-	case "python":
-		conf.Log.Printf("starting python plugin executable %s with script %s\n", conf.Config.Portable.PythonBin, pluginMeta.Executable)
-		cmd = exec.Command(conf.Config.Portable.PythonBin, pluginMeta.Executable, string(jsonArg))
-	default:
-		return nil, fmt.Errorf("unsupported language: %s", pluginMeta.Language)
+		case "python":
+			conf.Log.Printf("starting python plugin executable %s with script %s\n", conf.Config.Portable.PythonBin, pluginMeta.Executable)
+			cmd = exec.Command(conf.Config.Portable.PythonBin, pluginMeta.Executable, string(jsonArg))
+		default:
+			return fmt.Errorf("unsupported language: %s", pluginMeta.Language)
+		}
+		return nil
+	})
+	if err != nil {
+		return nil, fmt.Errorf("fail to start plugin %s: %v", pluginMeta.Name, err)
 	}
 	}
 	cmd.Stdout = conf.Log.Out
 	cmd.Stdout = conf.Log.Out
 	cmd.Stderr = conf.Log.Out
 	cmd.Stderr = conf.Log.Out