Bläddra i källkod

fix: plugin does not exited as expected

Yeuoly 1 år sedan
förälder
incheckning
34238db30b

+ 10 - 2
cmd/server/main.go

@@ -35,8 +35,10 @@ func setDefault(config *app.Config) {
 	setDefaultInt(&config.LifetimeStateGCInterval, 300)
 	setDefaultInt(&config.DifyInvocationConnectionIdleTimeout, 120)
 	setDefaultInt(&config.PluginRemoteInstallServerEventLoopNums, 8)
+	setDefaultInt(&config.PluginRemoteInstallingMaxConn, 128)
+	settDefaultBool(&config.PluginRemoteInstallingEnabled, true)
 
-	setDebugString(&config.ProcessCachingPath, "/tmp/dify-plugin-daemon-subprocesses")
+	settDefaultString(&config.ProcessCachingPath, "/tmp/dify-plugin-daemon-subprocesses")
 }
 
 func setDefaultInt[T constraints.Integer](value *T, defaultValue T) {
@@ -45,8 +47,14 @@ func setDefaultInt[T constraints.Integer](value *T, defaultValue T) {
 	}
 }
 
-func setDebugString(value *string, defaultValue string) {
+func settDefaultString(value *string, defaultValue string) {
 	if *value == "" {
 		*value = defaultValue
 	}
 }
+
+func settDefaultBool(value *bool, defaultValue bool) {
+	if !*value {
+		*value = defaultValue
+	}
+}

+ 4 - 0
internal/core/plugin_manager/lifetime.go

@@ -13,6 +13,7 @@ func lifetime(config *app.Config, r entities.PluginRuntimeInterface) {
 	configuration := r.Configuration()
 
 	log.Info("new plugin logged in: %s", configuration.Identity())
+	defer log.Info("plugin %s has exited", configuration.Identity())
 
 	// store plugin runtime
 	m.Store(configuration.Identity(), r)
@@ -42,6 +43,9 @@ func lifetime(config *app.Config, r entities.PluginRuntimeInterface) {
 		start_failed_times = 0
 		// start plugin
 		if err := r.StartPlugin(); err != nil {
+			if r.Stopped() {
+				break
+			}
 			log.Error("start plugin failed: %s, retry in 30s", err.Error())
 			time.Sleep(30 * time.Second)
 			if start_failed_times == 3 {

+ 2 - 0
internal/core/plugin_manager/remote_manager/type.go

@@ -62,4 +62,6 @@ func (r *RemotePluginRuntime) onDisconnected() {
 
 	// close response to stop current plugin
 	r.response.Close()
+
+	r.alive = false
 }