Repository navigation
fix(cache): guard empty repolist and add bounded cache polling - #1219
Open
neo0007777 wants to merge 1 commit into
Open
neo0007777 wants to merge 1 commit into
neo0007777 wants to merge 1 commit into
Conversation
- Short-circuit on empty or None repolist in get_uncached, retrieve_from_cache, and caching_wrapper to prevent PostgreSQL SyntaxError ('IN ()') and TypeError.
- Ensure psycopg2 connections are explicitly closed in try...finally blocks across cache_facade to prevent database connection leaks.
- Safely escape table names using psycopg2.sql.Identifier in retrieve_from_cache.
- Introduce wait_for_cache helper with deadline timeout and exponential backoff.
- Add unit test suite in tests/test_cache_facade.py.
Fixes chaoss#1218
Signed-off-by: Shiva Sharma <shivaumj@gmail.com>
Author
|
Hi @EngCaioFonseca, @cdolfi, @MoralCode - could you please review this PR when you have a moment? Why this is important (in short):
Thank you! |
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.
Summary of Changes
Closes #1218
This PR addresses critical failure modes in the cache layer and visualization workers:
Guard empty and
Nonerepolistqueries:get_uncached,retrieve_from_cache, andcaching_wrappernow checkif not repolistand short-circuit immediately with empty results ([]orpd.DataFrame()).psycopg2.errors.SyntaxError: syntax error at or near ")"caused byWHERE repo_id IN ()when a user clears repository selection or callbacks trigger prior to repo ID population.TypeError: 'NoneType' object is not iterablewhenNoneis passed.Database connection lifecycle cleanup:
try...finally: conn.close()acrosscache_query_results,get_uncached, andretrieve_from_cache.psycopg2,with pg.connect(...) as conn:only manages transactions (commit/rollback) and does not close the underlying connection upon exit, contributing to database connection exhaustion (Ensure 8Knot doesnt leak connections when materialized views not present #1170).Safe SQL table identifier escaping:
psycopg2.sql.Identifier(tablename)inretrieve_from_cacherather than raw Python string.format().Centralized bounded polling helper:
wait_for_cache(func_name, repolist, timeout=60, caller="")with deadline enforcement and exponential backoff (0.5s → 1.0s → 2.0s up to 5.0s) to provide a standardized, bounded polling utility for visualization callbacks.Unit test suite:
tests/test_cache_facade.pycovering all edge cases (empty lists,None, connection closing, identifier escaping, timeouts, and early returns) with all 8 tests passing.cc @EngCaioFonseca @cdolfi @MoralCode
Would appreciate your review on this PR! It resolves unhandled database syntax crashes and Celery worker thread exhaustion when repository selections change or initial queries load.