update dify 1.10.0 from 1.9.2 has error #20348

Closed
opened 2026-02-21 20:06:57 -05:00 by yindo · 1 comment
Owner

Originally created by @aijuntao on GitHub (Nov 16, 2025).

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.10.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Traceback (most recent call last):
File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, 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.12/site-packages/flask_restx/api.py", line 404, in wrapper
resp = resource(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/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.12/site-packages/flask_restx/resource.py", line 41, in dispatch_request
resp = meth(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/app/api/controllers/console/wraps.py", line 220, in decorated
return view(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/app/api/libs/login.py", line 75, in decorated_view
elif current_user is not None and not current_user.is_authenticated:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 318, in get
obj = instance._get_current_object()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 526, in _get_current_object
return get_name(local())
^^^^^^^
File "/app/api/libs/login.py", line 98, in
current_user: Any = LocalProxy(lambda: _get_user())
^^^^^^^^^^^
File "/app/api/libs/login.py", line 88, in _get_user
current_app.login_manager._load_user() # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask_login/login_manager.py", line 378, in _load_user
user = self._load_user_from_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/flask_login/login_manager.py", line 441, in _load_user_from_request
user = self._request_callback(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/extensions/ext_login.py", line 62, in load_user_from_request
logged_in_account = AccountService.load_logged_in_account(account_id=user_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/services/account_service.py", line 443, in load_logged_in_account
return AccountService.load_user(account_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/services/account_service.py", line 137, in load_user
account.set_tenant_id(current_tenant.tenant_id)
File "/app/api/models/account.py", line 162, in set_tenant_id
tenant_account_join = session.execute(query).first()
^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2351, in execute
return self._execute_internal(
^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2249, in _execute_internal
result: Result[Any] = compile_state_cls.orm_execute_statement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/context.py", line 306, in orm_execute_statement
result = conn.execute(
^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1419, in execute
return meth(
^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 526, in _execute_on_connection
return connection._execute_clauseelement(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1641, in _execute_clauseelement
ret = self._execute_context(
^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context
return self._exec_single_context(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context
self._handle_dbapi_exception(
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
self.dialect.do_execute(
File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 951, in do_execute
cursor.execute(statement, parameters)
File "/app/api/.venv/lib/python3.12/site-packages/psycogreen/gevent.py", line 32, in gevent_wait_callback
state = conn.poll()
^^^^^^^^^^^
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: terminating connection due to idle-session timeout
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.

[SQL: SELECT tenants.id, tenants.name, tenants.encrypt_public_key, tenants.plan, tenants.status, tenants.custom_config, tenants.created_at, tenants.updated_at, tenant_account_joins.id AS id_1, tenant_account_joins.tenant_id, tenant_account_joins.account_id, tenant_account_joins.current, tenant_account_joins.role, tenant_account_joins.invited_by, tenant_account_joins.created_at AS created_at_1, tenant_account_joins.updated_at AS updated_at_1
FROM tenants, tenant_account_joins
WHERE tenants.id = %(id_2)s::UUID AND tenant_account_joins.tenant_id = tenants.id AND tenant_account_joins.account_id = %(account_id_1)s::UUID]
[parameters: {'id_2': 'e48ce911-7f13-4a88-8086-8998638e1f7b', 'account_id_1': 'a77e2d0a-68f2-4e7d-9e53-b36fc7fdaad4'}]
(Background on this error at: https://sqlalche.me/e/20/e3q8)

✔️ Expected Behavior

fixed

Actual Behavior

No response

Originally created by @aijuntao on GitHub (Nov 16, 2025). ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.10.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce Traceback (most recent call last): File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request rv = self.dispatch_request() ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask/app.py", line 902, 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.12/site-packages/flask_restx/api.py", line 404, in wrapper resp = resource(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/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.12/site-packages/flask_restx/resource.py", line 41, in dispatch_request resp = meth(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/controllers/console/wraps.py", line 220, in decorated return view(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/app/api/libs/login.py", line 75, in decorated_view elif current_user is not None and not current_user.is_authenticated: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 318, in __get__ obj = instance._get_current_object() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/werkzeug/local.py", line 526, in _get_current_object return get_name(local()) ^^^^^^^ File "/app/api/libs/login.py", line 98, in <lambda> current_user: Any = LocalProxy(lambda: _get_user()) ^^^^^^^^^^^ File "/app/api/libs/login.py", line 88, in _get_user current_app.login_manager._load_user() # type: ignore ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_login/login_manager.py", line 378, in _load_user user = self._load_user_from_request(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/flask_login/login_manager.py", line 441, in _load_user_from_request user = self._request_callback(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/extensions/ext_login.py", line 62, in load_user_from_request logged_in_account = AccountService.load_logged_in_account(account_id=user_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/services/account_service.py", line 443, in load_logged_in_account return AccountService.load_user(account_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/services/account_service.py", line 137, in load_user account.set_tenant_id(current_tenant.tenant_id) File "/app/api/models/account.py", line 162, in set_tenant_id tenant_account_join = session.execute(query).first() ^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2351, in execute return self._execute_internal( ^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/session.py", line 2249, in _execute_internal result: Result[Any] = compile_state_cls.orm_execute_statement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/orm/context.py", line 306, in orm_execute_statement result = conn.execute( ^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1419, in execute return meth( ^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/sql/elements.py", line 526, in _execute_on_connection return connection._execute_clauseelement( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1641, in _execute_clauseelement ret = self._execute_context( ^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1846, in _execute_context return self._exec_single_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1986, in _exec_single_context self._handle_dbapi_exception( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception raise sqlalchemy_exception.with_traceback(exc_info[2]) from e File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context self.dialect.do_execute( File "/app/api/.venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 951, in do_execute cursor.execute(statement, parameters) File "/app/api/.venv/lib/python3.12/site-packages/psycogreen/gevent.py", line 32, in gevent_wait_callback state = conn.poll() ^^^^^^^^^^^ sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) FATAL: terminating connection due to idle-session timeout server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. [SQL: SELECT tenants.id, tenants.name, tenants.encrypt_public_key, tenants.plan, tenants.status, tenants.custom_config, tenants.created_at, tenants.updated_at, tenant_account_joins.id AS id_1, tenant_account_joins.tenant_id, tenant_account_joins.account_id, tenant_account_joins.current, tenant_account_joins.role, tenant_account_joins.invited_by, tenant_account_joins.created_at AS created_at_1, tenant_account_joins.updated_at AS updated_at_1 FROM tenants, tenant_account_joins WHERE tenants.id = %(id_2)s::UUID AND tenant_account_joins.tenant_id = tenants.id AND tenant_account_joins.account_id = %(account_id_1)s::UUID] [parameters: {'id_2': 'e48ce911-7f13-4a88-8086-8998638e1f7b', 'account_id_1': 'a77e2d0a-68f2-4e7d-9e53-b36fc7fdaad4'}] (Background on this error at: https://sqlalche.me/e/20/e3q8) ### ✔️ Expected Behavior fixed ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 20:06:57 -05:00
yindo closed this issue 2026-02-21 20:06:58 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Nov 16, 2025):

The PostgreSQL idle-session timeout error after upgrading to Dify 1.10.0 is likely related to changes in how database sessions are managed. Recent updates refactored the code to use explicit SQLAlchemy Session context managers (e.g., with Session(db.engine, expire_on_commit=False) as session:) instead of relying on the global db.session. This helps prevent connection leaks and ensures sessions are closed promptly, which is important for avoiding idle-session timeouts, especially in Docker deployments or high-concurrency environments. You can see these changes in the Account model and AccountService code, where sessions are now explicitly closed after use example.

If you have custom code or extensions, make sure they also use this pattern and do not leave sessions open. Also, review your PostgreSQL server's idle timeout settings and consider increasing them if your workload involves long-running requests. If the problem persists, check your Docker environment variables for any connection pool or timeout settings that may need adjustment. These changes were introduced to address connection leaks and should help prevent the error you are seeing reference.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Nov 16, 2025): <!-- Answer --> The PostgreSQL idle-session timeout error after upgrading to Dify 1.10.0 is likely related to changes in how database sessions are managed. Recent updates refactored the code to use explicit SQLAlchemy Session context managers (e.g., `with Session(db.engine, expire_on_commit=False) as session:`) instead of relying on the global `db.session`. This helps prevent connection leaks and ensures sessions are closed promptly, which is important for avoiding idle-session timeouts, especially in Docker deployments or high-concurrency environments. You can see these changes in the Account model and AccountService code, where sessions are now explicitly closed after use [example](https://github.com/langgenius/dify/blob/4a89403566c85eff76a959bc62be76f1e8af5ce6/api/models/account.py#L127-L168). If you have custom code or extensions, make sure they also use this pattern and do not leave sessions open. Also, review your PostgreSQL server's idle timeout settings and consider increasing them if your workload involves long-running requests. If the problem persists, check your Docker environment variables for any connection pool or timeout settings that may need adjustment. These changes were introduced to address connection leaks and should help prevent the error you are seeing [reference](https://github.com/langgenius/dify/pull/24656). <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/288a6325-b1dc-4b53-90d4-b245b975b2cf?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/28254)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#20348