langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
43.74k stars 6.08k forks source link

Node 代码执行 run failed: Failed to execute code, which is likely a network issue, please check if the sandbox service is running. ( Error: Failed to execute code, got status code 500, please check if the sandbox service is running ) #6412

Closed Tommickey2020gmail closed 1 month ago

Tommickey2020gmail commented 1 month ago

Self Checks

Dify version

0.6.14

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

环境:ubuntu 22.0.4 操作: git clone https://github.com/langgenius/dify.git 0614dify cd 0614dify/docker docker compose up -d 结果: 登录到dify web页面后,创建测试工作流,增加代码执行节点。运行报错: 错误信息:Node 代码执行 run failed: Failed to execute code, which is likely a network issue, please check if the sandbox service is running. ( Error: Failed to execute code, got status code 500, please check if the sandbox service is running )

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

dosubot[bot] commented 1 month ago

To resolve the issue of the code execution node failing with a status code 500 in your self-hosted Dify environment, follow these steps:

  1. Check Sandbox Service Configuration: Ensure the sandbox service is properly configured and running. Verify the following in your docker-compose.middleware.yaml file:

    sandbox:
     image: langgenius/dify-sandbox:0.2.1
     restart: always
     environment:
       API_KEY: ${API_KEY:-dify-sandbox}
       GIN_MODE: ${GIN_MODE:-release}
       WORKER_TIMEOUT: ${WORKER_TIMEOUT:-15}
       ENABLE_NETWORK: ${ENABLE_NETWORK:-true}
       HTTP_PROXY: ${HTTP_PROXY:-http://ssrf_proxy:3128}
       HTTPS_PROXY: ${HTTPS_PROXY:-http://ssrf_proxy:3128}
       SANDBOX_PORT: ${SANDBOX_PORT:-8194}
     volumes:
       - ./volumes/sandbox/dependencies:/dependencies
     networks:
       - ssrf_proxy_network
  2. Verify Service Status: Check if the sandbox service is running without issues:

    docker-compose -f docker-compose.middleware.yaml ps
  3. Network Configuration: Ensure there are no network connectivity issues between the sandbox service and other services. Use Docker's network inspection tools:

    docker network inspect ssrf_proxy_network
  4. Proxy Configuration: Ensure the ssrf_proxy service is correctly configured and running. The sandbox service relies on this proxy for network access.

  5. Environment Variables: Ensure your .env file is correctly configured. Relevant environment variables include:

    API_KEY=dify-sandbox
    GIN_MODE=release
    WORKER_TIMEOUT=15
    ENABLE_NETWORK=true
    HTTP_PROXY=http://ssrf_proxy:3128
    HTTPS_PROXY=http://ssrf_proxy:3128
    SANDBOX_PORT=8194
  6. Increase Timeout: Increase the timeout setting to handle longer requests:

    GUNICORN_TIMEOUT=360
  7. Debugging: Enable detailed error logging by setting DEBUG and FLASK_DEBUG to true:

    DEBUG=true
    FLASK_DEBUG=true

By verifying and adjusting these configurations, you should be able to resolve the issue causing the code execution node to fail with a status code 500 [1][2].

To continue talking to Dosu, mention @dosu.

crazywoola commented 1 month ago

Please provide the container logs of api and sandbox.

Tommickey2020gmail commented 1 month ago

Please provide the container logs of api and sandbox.

(base) ubuntu@XZ-2080Ti:~/dify/0614dify/docker$ docker logs docker-api-1 Running migrations None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used. Preparing database migration... Start database migration. INFO [alembic.runtime.migration] Context impl PostgresqlImpl. INFO [alembic.runtime.migration] Will assume transactional DDL. Database migration successful! None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used. [2024-07-18 22:58:14 +0000] [56] [INFO] Starting gunicorn 22.0.0 [2024-07-18 22:58:14 +0000] [56] [INFO] Listening at: http://0.0.0.0:5001 (56) [2024-07-18 22:58:14 +0000] [56] [INFO] Using worker: gevent [2024-07-18 22:58:14 +0000] [105] [INFO] Booting worker with pid: 105 2024-07-18 23:01:46,668.668 INFO [Dummy-1] [_client.py:1026] - HTTP Request: GET http://sandbox:8194/v1/sandbox/dependencies?language=python3 "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:01:46,673.673 ERROR [Dummy-1] [code_executor.py:196] - Failed to list dependencies: Failed to list dependencies, got status code 500, please check if the sandbox service is running Traceback (most recent call last): File "/app/api/core/helper/code_executor/code_executor.py", line 188, in _get_dependencies raise Exception(f'Failed to list dependencies, got status code {response.status_code}, please check if the sandbox service is running') Exception: Failed to list dependencies, got status code 500, please check if the sandbox service is running 2024-07-18 23:01:57,570.570 INFO [Thread-4 (_generate_worker)] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:02:57,545.545 INFO [Dummy-5] [_client.py:1026] - HTTP Request: GET http://sandbox:8194/v1/sandbox/dependencies?language=python3 "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:02:57,550.550 ERROR [Dummy-5] [code_executor.py:196] - Failed to list dependencies: Failed to list dependencies, got status code 500, please check if the sandbox service is running Traceback (most recent call last): File "/app/api/core/helper/code_executor/code_executor.py", line 188, in _get_dependencies raise Exception(f'Failed to list dependencies, got status code {response.status_code}, please check if the sandbox service is running') Exception: Failed to list dependencies, got status code 500, please check if the sandbox service is running 2024-07-18 23:03:26,392.392 INFO [Thread-6 (_generate_worker)] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:04:08,699.699 INFO [Dummy-9] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:05:44,093.093 ERROR [Dummy-10] [app.py:838] - Exception on /console/api/oauth/login/google [GET] Traceback (most recent call last): File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(view_args) # type: ignore[no-any-return] File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/init.py", line 489, in wrapper resp = resource(args, kwargs) File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(kwargs) # type: ignore[no-any-return] File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/init.py", line 604, in dispatch_request resp = meth(args, kwargs) File "/app/api/controllers/console/auth/oauth.py", line 48, in get print(vars(oauth_provider)) TypeError: vars() argument must have dict attribute 2024-07-18 23:05:46,735.735 ERROR [Dummy-11] [app.py:838] - Exception on /console/api/oauth/login/github [GET] Traceback (most recent call last): File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request rv = self.dispatch_request() File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(view_args) # type: ignore[no-any-return] File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/init.py", line 489, in wrapper resp = resource(args, kwargs) File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view return current_app.ensure_sync(self.dispatch_request)(kwargs) # type: ignore[no-any-return] File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/init.py", line 604, in dispatch_request resp = meth(args, kwargs) File "/app/api/controllers/console/auth/oauth.py", line 48, in get print(vars(oauth_provider)) TypeError: vars() argument must have dict attribute 2024-07-18 23:05:55,472.472 INFO [Dummy-12] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:06:37,996.996 INFO [Dummy-13] [_client.py:1026] - HTTP Request: GET http://sandbox:8194/v1/sandbox/dependencies?language=python3 "HTTP/1.1 500 Internal Privoxy Error" 2024-07-18 23:06:37,999.999 ERROR [Dummy-13] [code_executor.py:196] - Failed to list dependencies: Failed to list dependencies, got status code 500, please check if the sandbox service is running Traceback (most recent call last): File "/app/api/core/helper/code_executor/code_executor.py", line 188, in _get_dependencies raise Exception(f'Failed to list dependencies, got status code {response.status_code}, please check if the sandbox service is running') Exception: Failed to list dependencies, got status code 500, please check if the sandbox service is running 2024-07-18 23:06:56,644.644 INFO [Thread-14 (_generate_worker)] [_client.py:1026] - HTTP Request: POST http://sandbox:8194/v1/sandbox/run "HTTP/1.1 500 Internal Privoxy Error"

(base) ubuntu@XZ-2080Ti:~/dify/0614dify/docker$ docker logs docker-sandbox-1 2024/07/18 22:56:52 setup.go:29: [INFO]initializing nodejs runner environment... 2024/07/18 22:56:52 setup.go:85: [INFO]nodejs runner environment initialized 2024/07/18 22:56:52 setup.go:31: [INFO]initializing python runner environment... 2024/07/18 22:56:52 setup.go:43: [INFO]python runner environment initialized 2024/07/18 22:56:52 config.go:86: [INFO]network has been enabled 2024/07/18 22:56:52 config.go:102: [INFO]using https proxy: http://ssrf_proxy:3128 2024/07/18 22:56:52 config.go:111: [INFO]using http proxy: http://ssrf_proxy:3128 2024/07/18 22:56:52 server.go:19: [INFO]config init success 2024/07/18 22:56:52 server.go:25: [INFO]runner dependencies init success 2024/07/18 22:56:52 server.go:41: [INFO]installing python dependencies... 2024/07/18 22:56:52 server.go:47: [INFO]python dependencies installed 2024/07/18 22:56:52 cocrrent.go:31: [INFO]setting max requests to 50 2024/07/18 22:56:52 cocrrent.go:13: [INFO]setting max workers to 4 [GIN] 2024/07/18 - 22:57:32 | 401 | 3.7µs | :: | GET "/squid-internal-dynamic/netdb"

Tommickey2020gmail commented 1 month ago

Please provide the container logs of api and sandbox.

(base) ubuntu@XZ-2080Ti:~/dify/0614dify/docker$ docker exec -it docker-api-1 /bin/bash root@ed808c2571be:/app/api# curl http://ssrf_proxy:3128

500 Internal Privoxy Error

500 Internal Privoxy Error

Privoxy encountered an error while processing your request:

Could not load template file no-server-data or one of its included components.

Please contact your proxy administrator.

If you are the proxy administrator, please put the required file(s)in the (confdir)/templates directory. The location of the (confdir) directory is specified in the main Privoxy config file. (It's typically the Privoxy install directory).

在docker-api-1容器里,不能访问ssrf_proxy:3128, 是不是这个问题导致?

crazywoola commented 1 month ago

Have you turned on the VPN on your server?

Tommickey2020gmail commented 1 month ago

Have you turned on the VPN on your server?

Yes,there are http_proxy and https_proxy setting in each container env, after docker compose up -d.

crazywoola commented 1 month ago

Have you turned on the VPN on your server?

Yes,there are http_proxy and https_proxy setting in each container env, after docker compose up -d.

Please try turn the VPN off and test the code block again to see if this resolved.

jiazhuouyang commented 1 week ago

你的服务器上开启了VPN吗?

是的,docker compose up -d之后,每个容器环境中都有http_proxy和https_proxy设置。

请问您的问题解决了吗?