Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

register_vector leaks dumper classes on every call

Đang mở
#168 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
postgresql, python
Lĩnh vực
backend, databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Python
Star
1.5k
Fork
100
Merge trung bình
13 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pgvector/pgvector-python

Tất cả issue của pgvector/pgvector-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.