Leaked instances of DuckDBPyType since 2.0

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

メンテナーはふだん 1 日以内に返信

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

評価

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

調査の方向性

Start by running the pure Python reproducer with DuckDB 2.0, then compare it with the torch and typing.overload scenario. The issue points to DuckDBPyConnection annotations being retained during shutdown and reports leaks in nanobind bindings, but names no source file or test. Done means the reproducer exits without nanobind leak reports.

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

説明

needs triage
What happens?

Since 2.0, our runtimes end with what looks like leaked instances of DuckDBPyType.

nanobind: leaked 27 instances!
 - leaked instance 0x64c7922f1c50 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922f1c10 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e85b0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e86d0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e85d0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8630 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8610 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8730 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922f1c70 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e87d0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8670 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8690 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8810 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922f1c30 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8590 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8770 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e87b0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e85f0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e86f0 of type "_duckdb._sqltypes.DuckDBPyType"
 - leaked instance 0x64c7922e8710 of type "_duckdb._sqltypes.DuckDBPyType"
 - ... skipped remainder
nanobind: leaked 6 types!
 - leaked type "_duckdb._sqltypes.DuckDBPyType"
 - leaked type "_duckdb.DuckDBPyConnection"
 - leaked type "FunctionNullHandling"
 - leaked type "PythonUDFType"
 - leaked type "ExplainType"
 - leaked type "PythonExceptionHandling"
nanobind: leaked 84 functions!
 - leaked function "extract_statements"
 - leaked function "__exit__"
 - leaked function "fetchdf"
 - leaked function "_statement_count"
 - leaked function "install_extension"
 - leaked function "array_type"
 - leaked function ""
 - leaked function "interrupt"
 - leaked function "_own_sources"
 - leaked function "torch"
 - ... skipped remainder
nanobind: this is likely caused by a reference counting issue in the binding code.
See https://nanobind.readthedocs.io/en/latest/refleaks.html
To Reproduce

It seems this is due to interaction with other libs, torch in particular, and typing.overload.

This is a pure Python reproducer

import ctypes

import duckdb

ctypes.pythonapi.Py_IncRef(ctypes.py_object(duckdb.DuckDBPyConnection))

Here is a more realistic scenario.

$ cat lib.py
import typing

import duckdb


class Wrapper:
    def __init__(self, con: duckdb.DuckDBPyConnection): ...


# typing.overload stores the function in typing._overload_registry, which is not
# released at shutdown once torch has been imported.
@typing.overload
def f(x: int) -> None: ...
$ cat repro_torch.py
"""duckdb + torch + a module with a typing.overload and a DuckDBPyConnection annotation."""
import torch  # noqa: F401

import lib  # noqa: F401

Running python repro_torch.py provides the same error message.

OS:

Ubuntu 26

DuckDB Version:

2.0

DuckDB Client:

Python

Hardware:

No response

Full Name:

Jakob Stigenberg

Affiliation:

Qubos Systematic

Did you include all relevant configuration (e.g., CPU architecture, Linux distribution) to reproduce the issue?
  • Yes, I have
Did you include all code required to reproduce the issue?
  • Yes, I have
Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

主要言語
Python
スター
203
フォーク
124
平均マージ
13時間 36分
マージ済み PR(30日)
61

環境構築

はじめの一歩

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

duckdb/duckdb-python のほかの issue

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

似ている issue

Python の issue をもっと見る

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

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