[PR #81] [MERGED] Fix: Convert shared class variables to instance variables to solve lock contention and CPU issues #128

Closed
opened 2026-02-15 21:15:53 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langgenius/dify-plugin-sdks/pull/81
Author: @hejuntt1014
Created: 4/8/2025
Status: Merged
Merged: 4/11/2025
Merged by: @Yeuoly

Base: mainHead: fix-request-reader-shared-lock-and-list


📝 Commits (1)

  • 72fa55a Fix: Convert shared class variables to instance variables in RequestReader to solve lock contention and CPU deadlock issues

📊 Changes

4 files changed (+72 additions, -19 deletions)

View changed files

📝 python/dify_plugin/core/server/__base/request_reader.py (+66 -19)
📝 python/dify_plugin/core/server/serverless/request_reader.py (+1 -0)
📝 python/dify_plugin/core/server/stdio/request_reader.py (+3 -0)
📝 python/dify_plugin/core/server/tcp/request_reader.py (+2 -0)

📄 Description

Problem

In the RequestReader class, the lock and readers variables are defined as class variables shared by all instances, causing lock contention and high CPU usage issues in high-concurrency scenarios.

Fix

  1. Converted class variables to instance variables to ensure each RequestReader instance has its own lock and readers list
  2. Added super().init() calls in subclasses to properly initialize instance variables
  3. Optimized lock usage by reducing lock holding time during filter operations
  4. Added error handling in the event loop to prevent high CPU usage during exceptions

Testing

This fix resolves the CPU 100% usage and system deadlock issues that occurred in high-concurrency scenarios.

Modified Files

  • python/dify_plugin/core/server/__base/request_reader.py
  • python/dify_plugin/core/server/serverless/request_reader.py
  • python/dify_plugin/core/server/stdio/request_reader.py
  • python/dify_plugin/core/server/tcp/request_reader.py

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langgenius/dify-plugin-sdks/pull/81 **Author:** [@hejuntt1014](https://github.com/hejuntt1014) **Created:** 4/8/2025 **Status:** ✅ Merged **Merged:** 4/11/2025 **Merged by:** [@Yeuoly](https://github.com/Yeuoly) **Base:** `main` ← **Head:** `fix-request-reader-shared-lock-and-list` --- ### 📝 Commits (1) - [`72fa55a`](https://github.com/langgenius/dify-plugin-sdks/commit/72fa55ab93f5dea320eecc70435b09af56b40414) Fix: Convert shared class variables to instance variables in RequestReader to solve lock contention and CPU deadlock issues ### 📊 Changes **4 files changed** (+72 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `python/dify_plugin/core/server/__base/request_reader.py` (+66 -19) 📝 `python/dify_plugin/core/server/serverless/request_reader.py` (+1 -0) 📝 `python/dify_plugin/core/server/stdio/request_reader.py` (+3 -0) 📝 `python/dify_plugin/core/server/tcp/request_reader.py` (+2 -0) </details> ### 📄 Description ## Problem In the RequestReader class, the lock and readers variables are defined as class variables shared by all instances, causing lock contention and high CPU usage issues in high-concurrency scenarios. ## Fix 1. Converted class variables to instance variables to ensure each RequestReader instance has its own lock and readers list 2. Added super().__init__() calls in subclasses to properly initialize instance variables 3. Optimized lock usage by reducing lock holding time during filter operations 4. Added error handling in the event loop to prevent high CPU usage during exceptions ## Testing This fix resolves the CPU 100% usage and system deadlock issues that occurred in high-concurrency scenarios. ## Modified Files - python/dify_plugin/core/server/__base/request_reader.py - python/dify_plugin/core/server/serverless/request_reader.py - python/dify_plugin/core/server/stdio/request_reader.py - python/dify_plugin/core/server/tcp/request_reader.py --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 21:15:53 -05:00
yindo closed this issue 2026-02-15 21:15:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify-plugin-sdks#128