{"record":{"id":"6ac421b7735acf8a","repo":"crewAIInc/crewAI","slug":"pool-lock-not-initialized","errorCode":null,"errorMessage":"Pool lock not initialized","messagePattern":"Pool lock 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":163,"sourceCode":"                        ],\n                        check=True,\n                    )\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,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/crewAIInc/crewAI/blob/754d7323beb2fd042e33444a115ea2d5a47193f0/lib/crewai-tools/src/crewai_tools/tools/snowflake_search_tool/snowflake_search_tool.py#L145-L181","documentation":"SnowflakeSearchTool._get_connection raises RuntimeError(\"Pool lock not initialized\") when self._pool_lock is None. The lock (and pool) are only created in the dependency-bootstrap path inside __init__ when packages are present; if initialization was skipped or interrupted, async connection acquisition refuses to proceed rather than racing on an unprotected pool.","triggerScenarios":"The Snowflake packages were absent at __init__ (so _pool_lock was never assigned), and _get_connection is called afterwards; or object state was mutated/cleared externally (e.g. after close/cleanup) while a query is still in flight.","commonSituations":"Swallowing the ImportError from construction (try/except pass) and then calling the tool; reusing a tool instance after its resources were torn down; partial initialization when the auto-install prompt was declined.","solutions":["Ensure the Snowflake dependencies are installed BEFORE constructing the tool so __init__ fully initializes the pool, lock, and thread pool.","Do not catch-and-continue around tool construction — the ImportError at init is the root cause; fix it instead.","Recreate the SnowflakeSearchTool instance if its state was cleared rather than reusing it."],"exampleFix":"# before\ntry:\n    tool = SnowflakeSearchTool(config=cfg)\nexcept ImportError:\n    pass  # later: await tool._get_connection() -> RuntimeError\n\n# after\n# pip install snowflake-connector-python snowflake-sqlalchemy cryptography\ntool = SnowflakeSearchTool(config=cfg)","handlingStrategy":"validation","validationCode":"tool = SnowflakeSearchTool(config=cfg)  # raises ImportError if deps missing\nif getattr(tool, \"_pool_lock\", None) is None:\n    raise RuntimeError(\"Tool not fully initialized; install Snowflake dependencies and recreate\")","typeGuard":null,"tryCatchPattern":"try:\n    conn = await tool._get_connection()\nexcept RuntimeError as e:\n    if \"not initialized\" in str(e):\n        tool = SnowflakeSearchTool(config=cfg)  # recreate after fixing deps\n        conn = await tool._get_connection()\n    else:\n        raise","preventionTips":["Never swallow the ImportError raised during tool construction.","Treat 'not initialized' RuntimeErrors as an initialization bug, not a transient query failure."],"tags":["snowflake","initialization","concurrency","runtime"],"backgroundTag":null,"analyzedSha":"754d7323beb2fd042e33444a115ea2d5a47193f0","analyzedAt":"2026-08-15T04:06:56.746Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}