Yeuoly 9 miesięcy temu
rodzic
commit
ffabaa5625

+ 6 - 0
docker/local/Dockerfile

@@ -6,6 +6,9 @@ COPY . /app
 # set working directory
 WORKDIR /app
 
+# using goproxy if you have network issues
+# ENV GOPROXY=https://goproxy.cn,direct
+
 # build
 RUN go build -o /app/main cmd/server/main.go
 
@@ -18,4 +21,7 @@ RUN apt-get update && apt-get install -y python3.10 python3.10-venv python3.10-d
     && apt-get clean \
     && rm -rf /var/lib/apt/lists/*
 
+ENV PLATFORM=local
+ENV GIN_MODE=release
+
 CMD ["/app/main"]

+ 7 - 1
docker/serverless/Dockerfile

@@ -6,11 +6,17 @@ COPY . /app
 # set working directory
 WORKDIR /app
 
+# using goproxy if you have network issues
+# ENV GOPROXY=https://goproxy.cn,direct
+
 # build
-RUN go build -o /app/main cmd/server/main.go
+RUN CGO_ENABLED=0 GOOS=linux go build -o /app/main cmd/server/main.go
 
 FROM alpine:latest
 
 COPY --from=builder /app/main /app/main
 
+ENV PLATFORM=aws_lambda
+ENV GIN_MODE=release
+
 CMD ["./main"]

+ 16 - 0
internal/core/plugin_manager/remote_manager/hooks.go

@@ -45,6 +45,9 @@ type DifyServer struct {
 	plugins_lock *sync.RWMutex
 
 	shutdown_chan chan bool
+
+	max_conn     int32
+	current_conn int32
 }
 
 func (s *DifyServer) OnBoot(c gnet.Engine) (action gnet.Action) {
@@ -99,6 +102,10 @@ func (s *DifyServer) OnClose(c gnet.Conn, err error) (action gnet.Action) {
 	delete(s.plugins, c.Fd())
 	s.plugins_lock.Unlock()
 
+	if plugin == nil {
+		return gnet.None
+	}
+
 	// close plugin
 	plugin.onDisconnected()
 
@@ -108,6 +115,9 @@ func (s *DifyServer) OnClose(c gnet.Conn, err error) (action gnet.Action) {
 			if err := plugin.Unregister(); err != nil {
 				log.Error("unregister plugin failed, error: %v", err)
 			}
+
+			// decrease current connection
+			atomic.AddInt32(&s.current_conn, -1)
 		}
 	}
 
@@ -271,6 +281,12 @@ func (s *DifyServer) onMessage(runtime *RemotePluginRuntime, message []byte) {
 			return
 		}
 
+		atomic.AddInt32(&s.current_conn, 1)
+		if atomic.LoadInt32(&s.current_conn) > int32(s.max_conn) {
+			close([]byte("server is busy now, please try again later\n"))
+			return
+		}
+
 		// fill in default values
 		runtime.Config.FillInDefaultValues()
 

+ 1 - 0
internal/types/app/default.go

@@ -18,6 +18,7 @@ func (config *Config) SetDefault() {
 	setDefaultBool(&config.PluginRemoteInstallingEnabled, true)
 	setDefaultBool(&config.PluginEndpointEnabled, true)
 	setDefaultString(&config.DBSslMode, "disable")
+	setDefaultString(&config.PluginStoragePath, "./storage/plugin")
 	setDefaultString(&config.PluginMediaCachePath, "./storage/assets")
 	setDefaultString(&config.PersistenceStorageLocalPath, "./storage/persistence")
 	setDefaultString(&config.ProcessCachingPath, "./storage/subprocesses")