diff --git a/go.mod b/go.mod index e7194815..ad61f7ff 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/langgenius/dify-sandbox go 1.24.0 -toolchain go1.23.3 - require ( github.com/gin-gonic/gin v1.10.0 github.com/google/uuid v1.6.0 diff --git a/internal/core/runner/nodejs/setup.go b/internal/core/runner/nodejs/setup.go index abb49ce2..2a883097 100644 --- a/internal/core/runner/nodejs/setup.go +++ b/internal/core/runner/nodejs/setup.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path" + "sync" "github.com/langgenius/dify-sandbox/internal/utils/log" ) @@ -17,6 +18,8 @@ const ( //go:embed nodejs.so var nodejs_lib []byte +var libAvailableOnce sync.Once +var libAvailableResult bool //go:embed dependens var nodejs_dependens embed.FS // it's a directory @@ -85,9 +88,12 @@ func releaseLibBinary() { } func checkLibAvaliable() bool { - if _, err := os.Stat(path.Join(LIB_PATH, LIB_NAME)); err != nil { - return false - } - - return true + libAvailableOnce.Do(func() { + if _, err := os.Stat(path.Join(LIB_PATH, LIB_NAME)); err != nil { + libAvailableResult = false + return + } + libAvailableResult = true + }) + return libAvailableResult } diff --git a/internal/core/runner/python/setup.go b/internal/core/runner/python/setup.go index f59e866e..94928b73 100644 --- a/internal/core/runner/python/setup.go +++ b/internal/core/runner/python/setup.go @@ -8,6 +8,7 @@ import ( "path" "regexp" "strings" + "sync" "github.com/langgenius/dify-sandbox/internal/static" @@ -19,6 +20,8 @@ import ( //go:embed python.so var python_lib []byte +var libAvailableOnce sync.Once +var libAvailableResult bool const ( LIB_PATH = "/var/sandbox/sandbox-python" @@ -63,11 +66,14 @@ func releaseLibBinary(force_remove_old_lib bool) { } func checkLibAvaliable() bool { - if _, err := os.Stat(path.Join(LIB_PATH, LIB_NAME)); err != nil { - return false - } - - return true + libAvailableOnce.Do(func() { + if _, err := os.Stat(path.Join(LIB_PATH, LIB_NAME)); err != nil { + libAvailableResult = false + return + } + libAvailableResult = true + }) + return libAvailableResult } func ExtractOnelineDepency(dependency string) (string, string) {