Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

register_vector leaks dumper classes on every call

オープン
#168 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
postgresql, python
領域
backend, databases

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Python
スター
1.5k
フォーク
100
平均マージ
13分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pgvector/pgvector-python のほかの issue

pgvector/pgvector-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。