You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[DBMON-6589] Clean up dangling references on cancel to improve GC (#23640)
* Close and dereference main db connection on cancel
* Remove unused db_pool reference
* Avoid extra reference to db_pool
* Deference cyclical check variable on shutdown
* Clear functools.partial closures in cancel() to release pool references
_dynamic_queries holds partial(db_pool.get_connection, ...) closures
and _query_manager.executor holds a partial(self.execute_query_raw, db=self.db)
closure. Both root the check instance and pool manager in memory after cancel.
* Null _job_loop_future after join in cancel() to release completed Futures
* dbms="postgres", _compiled_patterns_cache ⌘K to generate command ok next commit message suggestion Null _job_loop_future after join in cancel() to release completed Futures Completed Future objects are lightweight but keep the async job reachable in the reference graph. Nulling them immediately after .result() returns removes an unnecessary link that delays GC of the check instance. ok next Let me check the current state of each _shutdown method and the caches each job holds. Now I'll update each _shutdown to clear caches. StatementMetrics -- _full_statement_text_cache, _state, _query_calls_cache, _baseline_metrics: self._check = None self._full_statement_text_cache = None self._state = None self._query_calls_cache = None self._baseline_metrics = None except Exception: StatementSamples -- _collection_strategy_cache, _explain_errors_cache, _explained_statements_ratelimiter, _seen_samples_ratelimiter, _raw_statement_text_cache: self._check = None self._collection_strategy_cache = None self._explain_errors_cache = None self._explained_statements_ratelimiter = None self._seen_samples_ratelimiter = None self._raw_statement_text_cache = None except Exception: Metadata -- _schema_collector (holds back-ref to check) and _compiled_patterns_cache: self._check = None self._schema_collector = None self._compiled_patterns_cache = None except Exception: DataObservability only has a small _last_execution dict -- not worth clearing. Its _shutdown already just nulls _check, which is sufficient. All pre-existing. Done. Ready for your commit. commit message suggestion Clear caches in async job shutdown callbacks to free memory eagerly
* Add changelog
* Only invoke shutdown logic is cancel called
* Update tests
* Call shutdown explicitly
* Find and break cyclical references on cancel
0 commit comments