[PR #30150] fix(api): move cache invalidation outside redis lock to prevent timeout #32707

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

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

State: closed
Merged: Yes


Summary

Fixes #30149

Move ToolProviderListCache.invalidate_cache() outside the Redis lock in add_builtin_tool_provider to prevent lock timeout errors.

Problem

After #29101 introduced tool provider list caching, users are experiencing lock timeout errors:

{"code":"invalid_param","message":"Cannot release a lock that's no longer owned","status":400}

The 20-second lock timeout can be exceeded when:

  • validate_credentials() makes slow external API calls (e.g., OAuth token exchange)
  • invalidate_cache() uses scan_iter which scans the entire Redis keyspace

Solution

Move invalidate_cache() outside the lock since cache invalidation doesn't need to be atomic with the database write.

Also specify the "builtin" type to avoid unnecessary key scanning via scan_iter.

Test plan

  • Verify OAuth credential flow completes without lock timeout errors
  • Verify tool provider list cache is properly invalidated after adding credentials

🤖 Generated with Claude Code

**Original Pull Request:** https://github.com/langgenius/dify/pull/30150 **State:** closed **Merged:** Yes --- ## Summary Fixes #30149 Move `ToolProviderListCache.invalidate_cache()` outside the Redis lock in `add_builtin_tool_provider` to prevent lock timeout errors. ## Problem After #29101 introduced tool provider list caching, users are experiencing lock timeout errors: ```json {"code":"invalid_param","message":"Cannot release a lock that's no longer owned","status":400} ``` The 20-second lock timeout can be exceeded when: - `validate_credentials()` makes slow external API calls (e.g., OAuth token exchange) - `invalidate_cache()` uses `scan_iter` which scans the entire Redis keyspace ## Solution Move `invalidate_cache()` outside the lock since cache invalidation doesn't need to be atomic with the database write. Also specify the `"builtin"` type to avoid unnecessary key scanning via `scan_iter`. ## Test plan - [x] Verify OAuth credential flow completes without lock timeout errors - [x] Verify tool provider list cache is properly invalidated after adding credentials --- 🤖 Generated with [Claude Code](https://claude.com/claude-code)
yindo added the pull-request label 2026-02-21 20:51:55 -05:00
yindo closed this issue 2026-02-21 20:51:55 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#32707