fix(hooks): remove id(config) from get_global_client cache key to stop unbounded growth#3179
Open
nankingjing wants to merge 1 commit into
Open
Conversation
The shared VikingClient cache in openviking_hooks.get_global_client keyed on (workspace_id, running_loop_id, id(config)). Because id() returns the in-memory address and config objects are rebuilt on every fresh request, each new config created a new cache entry — unbounded growth, leak. Key on (workspace_id, running_loop_id) only. The two genuine reasons to create a new client are: - different workspace (admin/scoping) - different running event loop (loop-bound asyncio primitives) config is forwarded to the cached client only on cache miss (i.e. the first call for a given workspace + loop), which matches the original intent — a single client per (workspace, loop). 5 regression tests in tests/unit/test_global_client_cache.py cover: - reuse across rotating config objects (regression) - cache size does not grow with repeated calls - different workspaces still get distinct clients - None workspace normalized to '__default__' - cache key shape is exactly 2-tuple
Contributor
Author
| Self-reviewed: diff is correct, minimal, and well-tested. No issues found. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
The shared VikingClient cache in
openviking_hooks.get_global_clientkeyed on(workspace_id, running_loop_id, id(config)). Becauseid()returns the in-memory address and config objects are rebuilt on every fresh request, each new config created a new cache entry — unbounded growth, leak.The two genuine reasons to create a new client are different workspace (admin/scoping) and different running event loop (loop-bound asyncio primitives). The cache key was over-specified by including a non-stable handle.
Fix
configis forwarded to the cached client only on cache miss (the first call for a given workspace + loop), matching the original intent — one client per (workspace, loop).Regression tests
5 tests in
tests/unit/test_global_client_cache.py:workspace_id=Nonenormalized to stable default keyid(config))All 5 pass locally.