rusackas commented on code in PR #40237:
URL: https://github.com/apache/superset/pull/40237#discussion_r3300738205


##########
superset/models/core.py:
##########
@@ -94,6 +94,12 @@
 metadata = Model.metadata  # pylint: disable=no-member
 logger = logging.getLogger(__name__)
 
+# Per-process SQLAlchemy engine cache (#27897). Key is
+# (database_id, str(sqlalchemy_url), repr(sorted(engine_kwargs.items()))).
+# Populated only when ``nullpool=False`` — pooled engines are the only ones
+# that benefit from process-wide reuse.
+_ENGINE_CACHE: dict[tuple[Any, ...], Engine] = {}

Review Comment:
   Good catch — addressed in 415b932cf7.
   
   **Short answer:** URL/kwargs changes already produce a new cache key, so 
stale engines are never *served* after a config change. But the old engine 
would sit in `_ENGINE_CACHE` consuming memory until the process restarted.
   
   **What 415b932cf7 adds:** `_evict_engine_cache`, wired into the existing 
`after_update` and `after_delete` SQLAlchemy event hooks already at the bottom 
of `core.py`. On any database save or delete it drops all cache entries for 
that `database_id`, so:
   - password rotation / host change → old engine evicted immediately
   - SSH tunnel reconfig → same (the local bind address changes the URL string, 
so the old key is evicted)
   - database deletion → engine freed, no memory leak
   
   A test `test_engine_cache_evicted_on_update_and_delete` covers the 
multi-entry eviction and confirms sibling databases are unaffected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to