Database Connection Pool Exhaustion with High Concurrency on Dify Workflows #14703

Closed
opened 2026-02-21 19:18:23 -05:00 by yindo · 5 comments
Owner

Originally created by @dlmu-lq on GitHub (Jun 18, 2025).

Originally assigned to: @dlmu-lq on GitHub.

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

I attempted high concurrent access to Dify's workflows (where one node has a long IO wait for an HTTP request) and found that it leads to the exhaustion of the database connection pool. The issue was identified as the misuse of db.session, which wasn't properly closed before executing long-duration requests, causing db.session to only be released after the entire request is completed. Consequently, this leads to the exhaustion of the database connection pool under high concurrency.

2. Additional context or comments

Similar issues might arise in other scenarios such as agent and chatflow. I have locally modified the workflow execution process, and after stress testing, the issue was resolved. I am willing to contribute the changes.

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @dlmu-lq on GitHub (Jun 18, 2025). Originally assigned to: @dlmu-lq on GitHub. ### Self Checks - [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 (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### 1. Is this request related to a challenge you're experiencing? Tell me about your story. I attempted high concurrent access to Dify's workflows (where one node has a long IO wait for an HTTP request) and found that it leads to the exhaustion of the database connection pool. The issue was identified as the misuse of db.session, which wasn't properly closed before executing long-duration requests, causing db.session to only be released after the entire request is completed. Consequently, this leads to the exhaustion of the database connection pool under high concurrency. ### 2. Additional context or comments Similar issues might arise in other scenarios such as agent and chatflow. I have locally modified the workflow execution process, and after stress testing, the issue was resolved. I am willing to contribute the changes. ### 3. Can you help us with this feature? - [x] I am interested in contributing to this feature.
yindo added the 🐞 bug label 2026-02-21 19:18:23 -05:00
yindo closed this issue 2026-02-21 19:18:24 -05:00
Author
Owner

@Blackoutta commented on GitHub (Jun 26, 2025):

I've also encountered the same issue. Is there a fix for PR now? What changes did you make?

@Blackoutta commented on GitHub (Jun 26, 2025): I've also encountered the same issue. Is there a fix for PR now? What changes did you make?
Author
Owner

@alterxyz commented on GitHub (Jun 27, 2025):

Please feel free to make a pull request!

@alterxyz commented on GitHub (Jun 27, 2025): Please feel free to make a pull request!
Author
Owner

@dlmu-lq commented on GitHub (Jun 30, 2025):

@Blackoutta @alterxyz I have made a PR. Although it has not met my expectations yet, there has been a significant improvement in performance. I haven't found any other optimization points for now.

@dlmu-lq commented on GitHub (Jun 30, 2025): @Blackoutta @alterxyz I have made a PR. Although it has not met my expectations yet, there has been a significant improvement in performance. I haven't found any other optimization points for now.
Author
Owner

@Colstuwjx commented on GitHub (Jul 10, 2025):

HI @dlmu-lq , I've also met a similar issue #21939 , even introduced your fix commit, it still exists. The connection number would rapidly increase when someone called workflow execution which included a parallel iteration execution + llm + kb node + code block execution .

@Colstuwjx commented on GitHub (Jul 10, 2025): HI @dlmu-lq , I've also met a similar issue #21939 , even introduced your fix commit, it still exists. The connection number would rapidly increase when someone called workflow execution which included a parallel iteration execution + llm + kb node + code block execution .
Author
Owner

@Ruyu0224 commented on GitHub (Jul 11, 2025):

anyone solving the problem?Please help me solve it

@Ruyu0224 commented on GitHub (Jul 11, 2025): anyone solving the problem?Please help me solve it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#14703