{"record":{"id":"5dc781cb1205d9f2","repo":"crewAIInc/crewAI","slug":"connection-pool-not-initialized","errorCode":null,"errorMessage":"Connection pool not initialized","messagePattern":"Connection pool not initialized","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py","lineNumber":165,"sourceCode":"                    )\n\n                    self._connection_pool = []\n                    self._pool_lock = threading.Lock()\n                    self._thread_pool = ThreadPoolExecutor(max_workers=self.pool_size)\n                except subprocess.CalledProcessError as e:\n                    raise ImportError(\"Failed to install Snowflake dependencies\") from e\n            else:\n                raise ImportError(\n                    \"Snowflake dependencies not found. Please install them by running \"\n                    \"`uv add cryptography snowflake-connector-python snowflake-sqlalchemy`\"\n                ) from None\n\n    async def _get_connection(self) -> SnowflakeConnection:\n        \"\"\"Get a connection from the pool or create a new one.\"\"\"\n        if self._pool_lock is None:\n            raise RuntimeError(\"Pool lock not initialized\")\n        if self._connection_pool is None:\n            raise RuntimeError(\"Connection pool not initialized\")\n        with self._pool_lock:\n            if self._connection_pool:\n                return self._connection_pool.pop()\n        return await asyncio.get_event_loop().run_in_executor(\n            self._thread_pool, self._create_connection\n        )\n\n    def _create_connection(self) -> SnowflakeConnection:\n        \"\"\"Create a new Snowflake connection.\"\"\"\n        conn_params: dict[str, Any] = {\n            \"account\": self.config.account,\n            \"user\": self.config.user,\n            \"warehouse\": self.config.warehouse,\n            \"database\": self.config.database,\n            \"schema\": self.config.snowflake_schema,\n            \"role\": self.config.role,\n            \"session_parameters\": self.config.session_parameters,\n        }","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py#L147-L183","documentation":"SnowflakeSearchTool._get_connection raises RuntimeError(\"Connection pool not initialized\") when self._connection_pool is None. Like the pool-lock check, it guards the async path against use of a half-initialized tool: the pool list is created during __init__ only when the Snowflake dependency branch completes successfully.","triggerScenarios":"Calling _run/_get_connection on a tool whose __init__ did not complete the dependency branch (packages missing, install declined or failed), or after pool state was reset; the lock check fires first if both are None, so this specific message means _pool_lock exists but the pool list does not.","commonSituations":"State cleared during close/cleanup while a concurrent query still runs; subclasses that override or interfere with __init__ initialization order; swallowing init errors and continuing.","solutions":["Install the Snowflake dependencies and re-instantiate the tool so __init__ creates the pool.","If subclassing, ensure super().__init__() runs and do not clear _connection_pool while queries are in flight.","Avoid reusing an instance after cleanup; create a fresh one per session."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if getattr(tool, \"_connection_pool\", None) is None:\n    raise RuntimeError(\"Connection pool missing; re-create the tool with Snowflake deps installed\")\nresult = await tool._run(query=sql)","typeGuard":null,"tryCatchPattern":"try:\n    await tool._run(query=sql)\nexcept RuntimeError as e:\n    if \"Connection pool not initialized\" in str(e):\n        # recreate instance; do not retry on the broken one\n        raise","preventionTips":["Ensure __init__ completes successfully before any query path runs.","Avoid clearing pool state on a live instance; create a new instance per lifecycle."],"tags":["snowflake","initialization","connection-pool","runtime"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}