[PR #26406] improve: Explicitly delete task Redis key on completion in AppQueueManager #31423

Closed
opened 2026-02-21 20:49:26 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/26406

State: closed
Merged: Yes


Closes #26404

Summary

This PR addresses the issue of potential Redis key accumulation by ensuring the task_belong_cache_key is deleted immediately after a task completes.

The AppQueueManager is modified to:

  1. Store the task's Redis key in an instance variable.
  2. Introduce a _clear_task_belong_cache method to perform the cleanup.
  3. Call this cleanup method from stop_listen to tie the key's lifecycle to the task's lifecycle.

This change improves resource management by relying on explicit cleanup rather than just Redis TTL expiration, leading to a more stable and efficient system.

Screenshots

Before

We can see a lot of accumulated keys related to workflows that have already finished.
image

After

No more accumulated keys
image

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/26406 **State:** closed **Merged:** Yes --- Closes #26404 ## Summary This PR addresses the issue of potential Redis key accumulation by ensuring the `task_belong_cache_key` is deleted immediately after a task completes. The `AppQueueManager` is modified to: 1. Store the task's Redis key in an instance variable. 2. Introduce a `_clear_task_belong_cache` method to perform the cleanup. 3. Call this cleanup method from `stop_listen` to tie the key's lifecycle to the task's lifecycle. This change improves resource management by relying on explicit cleanup rather than just Redis TTL expiration, leading to a more stable and efficient system. ## Screenshots ### Before We can see a lot of accumulated keys related to workflows that have already finished. <img width="791" height="295" alt="image" src="https://github.com/user-attachments/assets/88ff1637-ce39-488c-b0df-30f930791eb4" /> ### After No more accumulated keys <img width="832" height="308" alt="image" src="https://github.com/user-attachments/assets/e16d158a-8c5b-4428-9e94-eaf021eac7d6" /> ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:49:26 -05:00
yindo closed this issue 2026-02-21 20:49:26 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31423