MemPalace/mempalace · error · BackendError
pgvector client has been closed
Error message
pgvector client has been closed
What it means
Error "pgvector client has been closed" thrown in MemPalace/mempalace.
Source
Thrown at mempalace/backends/pgvector.py:526
def _connect(self):
try:
import psycopg
except ImportError as exc: # pragma: no cover - exercised only without the extra
raise BackendError(
"pgvector backend requires the optional 'psycopg' dependency; "
"install mempalace[pgvector]"
) from exc
# One client is shared across threads (PgVectorBackend caches a
# single instance per config), so the read-create-store on self._conn
# must hold the same lock _execute serializes on; unlocked, two
# first-connect threads each opened a connection and the loser leaked
# unclosed. The RLock makes the _execute -> _connect nesting safe. A
# stalled connect blocks peers under the lock the same way any
# in-flight query on this single shared connection already does.
with self._lock:
if self._closed:
raise BackendError("pgvector client has been closed")
if self._conn is not None and not getattr(self._conn, "closed", False):
return self._conn
try:
self._conn = psycopg.connect(self._config.dsn)
except Exception as exc: # noqa: BLE001 - surface any driver failure uniformly
raise BackendError(f"pgvector connection failed: {exc}") from exc
return self._conn
def _execute(self, sql: str, params=None, *, fetch: bool = False, many: bool = False):
with self._lock:
conn = self._connect()
try:
with conn.cursor() as cur:
if many:
cur.executemany(sql, params or [])
rows = None
else:
cur.execute(sql, params or [])View on GitHub (pinned to 06cb6987f0)
Solutions
- Do not use the client after close(); create a new pgvector client/connection
When it happens
Trigger: Thrown at mempalace/backends/pgvector.py:526 when the library encounters an invalid state.
Common situations: Client was closed (explicitly or via context manager) and then reused.
AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15).
Data as JSON: /api/errors/dd89a63822b36876.
Report an issue: GitHub.