diff --git a/api/duckdb_pool_simple.py b/api/duckdb_pool_simple.py index a53926af..439ab503 100644 --- a/api/duckdb_pool_simple.py +++ b/api/duckdb_pool_simple.py @@ -142,31 +142,10 @@ def get_connection(self, timeout: float = 5.0): raise finally: - # CRITICAL: Always return and clean connection + # CRITICAL: Always return connection to pool + # DuckDB connections are stateless - no need to test or reset if conn is not None: - try: - # Reset connection state (clears DuckDB internal caches) - # Use a simple query to clear any cached results - result = conn.execute("SELECT 1").fetchall() - del result - - # Force aggressive garbage collection to release memory - # This is critical for preventing memory leaks from DuckDB result sets - collected = gc.collect() - - # Log GC only for significant collections (reduces log noise) - if collected > 100: - logger.debug(f"Connection cleanup: collected {collected} objects") - - except Exception as e: - # If cleanup fails, connection may be closed - don't return it to pool - logger.warning(f"Connection cleanup failed ({e}) - connection not returned to pool") - conn = None # Mark as invalid so we don't return it - - finally: - # Always return connection to pool (if still valid) - if conn is not None: - self.pool.put(conn) + self.pool.put(conn) def get_metrics(self) -> Dict[str, Any]: """