{"record":{"id":"dd89a63822b36876","repo":"MemPalace/mempalace","slug":"pgvector-client-has-been-closed","errorCode":null,"errorMessage":"pgvector client has been closed","messagePattern":"pgvector client has been closed","errorType":"exception","errorClass":"BackendError","httpStatus":null,"severity":"error","filePath":"mempalace/backends/pgvector.py","lineNumber":526,"sourceCode":"\n    def _connect(self):\n        try:\n            import psycopg\n        except ImportError as exc:  # pragma: no cover - exercised only without the extra\n            raise BackendError(\n                \"pgvector backend requires the optional 'psycopg' dependency; \"\n                \"install mempalace[pgvector]\"\n            ) from exc\n        # One client is shared across threads (PgVectorBackend caches a\n        # single instance per config), so the read-create-store on self._conn\n        # must hold the same lock _execute serializes on; unlocked, two\n        # first-connect threads each opened a connection and the loser leaked\n        # unclosed. The RLock makes the _execute -> _connect nesting safe. A\n        # stalled connect blocks peers under the lock the same way any\n        # in-flight query on this single shared connection already does.\n        with self._lock:\n            if self._closed:\n                raise BackendError(\"pgvector client has been closed\")\n            if self._conn is not None and not getattr(self._conn, \"closed\", False):\n                return self._conn\n            try:\n                self._conn = psycopg.connect(self._config.dsn)\n            except Exception as exc:  # noqa: BLE001 - surface any driver failure uniformly\n                raise BackendError(f\"pgvector connection failed: {exc}\") from exc\n            return self._conn\n\n    def _execute(self, sql: str, params=None, *, fetch: bool = False, many: bool = False):\n        with self._lock:\n            conn = self._connect()\n            try:\n                with conn.cursor() as cur:\n                    if many:\n                        cur.executemany(sql, params or [])\n                        rows = None\n                    else:\n                        cur.execute(sql, params or [])","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/MemPalace/mempalace/blob/06cb6987f02610784fefbad4b2bd5d026d164ba6/mempalace/backends/pgvector.py#L508-L544","documentation":"Error \"pgvector client has been closed\" thrown in MemPalace/mempalace.","triggerScenarios":"Thrown at mempalace/backends/pgvector.py:526 when the library encounters an invalid state.","commonSituations":"Client was closed (explicitly or via context manager) and then reused.","solutions":["Do not use the client after close(); create a new pgvector client/connection"],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"06cb6987f02610784fefbad4b2bd5d026d164ba6","analyzedAt":"2026-08-15T03:03:36.213Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}