Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(api): raise gunicorn keep-alive above client idle reuse window (#44839)

S1Moncd7ed2c16073
diff --git a/api/docker/entrypoint.sh b/api/docker/entrypoint.sh
index 84efe23f963..44902ac5182 100755
--- a/api/docker/entrypoint.sh
+++ b/api/docker/entrypoint.sh
@@ -164,6 +164,7 @@ else
--worker-class ${SERVER_WORKER_CLASS:-geventwebsocket.gunicorn.workers.GeventWebSocketWorker} \
--worker-connections ${SERVER_WORKER_CONNECTIONS:-10} \
--timeout ${GUNICORN_TIMEOUT:-200} \
+ --keep-alive ${GUNICORN_KEEP_ALIVE:-10} \
app:socketio_app
fi
fi
diff --git a/docker/.env.example b/docker/.env.example
index 6e7f48d616b..7607eb30ff7 100644
--- a/docker/.env.example
+++ b/docker/.env.example
@@ -61,6 +61,10 @@ API_WEBSOCKET_WORKER_CLASS=geventwebsocket.gunicorn.workers.GeventWebSocketWorke
API_WEBSOCKET_WORKER_CONNECTIONS=1000
API_WEBSOCKET_GUNICORN_TIMEOUT=360
GUNICORN_TIMEOUT=360
+# Must stay above the idle connection reuse window of the HTTP clients that
+# pool connections to the API (Node's undici reuses a socket for 4s). 0
+# disables keep-alive.
+GUNICORN_KEEP_ALIVE=10
CELERY_WORKER_CLASS=
CELERY_WORKER_AMOUNT=4
CELERY_AUTO_SCALE=false
diff --git a/docker/envs/core-services/shared.env.example b/docker/envs/core-services/shared.env.example
index 44417e74b97..0f736eb56b7 100644
--- a/docker/envs/core-services/shared.env.example
+++ b/docker/envs/core-services/shared.env.example
@@ -328,6 +328,12 @@ TENCENT_VECTOR_DB_DATABASE=dify
BAIDU_VECTOR_DB_DATABASE=dify
EXPOSE_PLUGIN_DAEMON_PORT=5002
GUNICORN_TIMEOUT=360
+# Must stay above the idle connection reuse window of the HTTP clients that
+# pool connections to this server. Node's global fetch (undici) keeps a socket
+# idle for 4s before dropping it, so a shorter value here lets the server close
+# a connection the client still considers reusable, which surfaces as
+# intermittent ECONNRESET on server-side rendering. 0 disables keep-alive.
+GUNICORN_KEEP_ALIVE=10
CELERY_WORKER_AMOUNT=
CELERY_AUTO_SCALE=false
CELERY_MAX_WORKERS=