Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

register_vector leaks dumper classes on every call

Open
#168 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
postgresql, python
Domain
backend, databases

Research direction

Start with register_vector_info and the dumper classes in pgvector/psycopg/vector.py, then compare their registration with psycopg’s hstore.py example linked in the issue. Use the supplied reproduction with psycopg’s C extension to check class counts before and after repeated calls; done means the dumper classes are no longer retained after contexts are deleted.

Written by the indexing model from the issue text.

Description

Hi!
Investigating a memory leak in our API, we found out that register_vector (and register_vector_async) creates 8 classes on every call that are never garbage collected if psycopg's C extension is in use, even after the connection is closed.

This is because these classes are stored by psycopg in a dict shared by the whole python process, and never cleared.

pgvector python 0.4.2 (but the code has not been updated on master) and psycopg 3.3.2

To reproduce:

import gc
from types import SimpleNamespace

import psycopg
from pgvector.psycopg.vector import (
    VectorBinaryDumper,
    VectorDumper,
    register_vector_info,
)
from psycopg.adapt import AdaptersMap
from psycopg.types import TypeInfo


def count() -> int:
    gc.collect()
    return sum(
        1
        for base in (VectorDumper, VectorBinaryDumper)
        for c in base.__subclasses__()
        if c.__name__ == ""
    )


print(psycopg.__version__, psycopg.pq.__impl__)
before = count()
for _ in range(1000):
    ctx = SimpleNamespace(adapters=AdaptersMap(psycopg.adapters))
    register_vector_info(ctx, TypeInfo("vector", 16385, 16386))
    del ctx
print("leaked dumper classes:", count() - before)  # expected 0, prints 2000

Caching these classes as done by psycopg could fix the issue : https://github.com/psycopg/psycopg/blob/99356800e90aa0e7b604f652d714ef0f33422b47/psycopg/psycopg/types/hstore.py#L225

Dominant language
Python
Stars
1.5k
Forks
100
Avg merge
13m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pgvector/pgvector-python

All issues in pgvector/pgvector-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.