nanobind: leaked ... when a DuckDB type is referenced in overload signature and numpy is imported
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
調査の方向性
Start with the reproduction script in the issue: it needs only typing.overload referencing duckdb.DuckDBPyConnection plus import numpy, and the leak appears at interpreter exit. Run it with uv run --script to confirm the nanobind warnings. The cause is a reference-counting problem in the nanobind binding code, so the work is tracing which type or function objects are not released, which needs familiarity with nanobind. Done means the script exits without the leak warnings.
索引モデルが issue の本文から書いたものです。
説明
What happens?
When the interpreter exits, duckdb 2.0.0 prints nanobind leak warnings if both of these are true:
- a DuckDB type (e.g. DuckDBPyConnection) is referenced from a typing.overload signature, which typing keeps in its module-level overload registry until shutdown
- numpy is imported (torch 2.6.0 triggers it the same way)
nanobind: leaked 27 instances!
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 "fetchone"
- leaked function "fetch_df"
- leaked function "__exit__"
- leaked function "_result_as_arrow"
- leaked function ""
- leaked function "abort"
- leaked function "append"
- leaked function "interrupt"
- leaked function "dtype"
- leaked function "_register_values"
- ... 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
with duckdb_nanobind_leak.py as follows
# /// script
# requires-python = ">=3.13"
# dependencies = ["duckdb==2.0.0", "numpy==2.5.2"]
# ///
"""duckdb 2.0.0 prints "nanobind: leaked ..." at interpreter exit.
Run: uv run --script duckdb_nanobind_leak.py
Triggered when a DuckDB type is referenced from a `typing.overload` signature (typing keeps overloads in a
module-level registry until shutdown) and numpy is imported. Without the overload, or without numpy, exit is clean.
torch (2.6.0) triggers it the same way as numpy.
"""
from typing import overload
import duckdb
import numpy
@overload
def connect(database: str) -> duckdb.DuckDBPyConnection: ...
@overload
def connect(database: None) -> None: ...
def connect(database):
return None if database is None else duckdb.connect(database)
run uv run --script duckdb_nanobind_leak.py
OS:
x86_64
DuckDB Version:
2.0.0
DuckDB Client:
Python
Hardware:
No response
Full Name:
Bartosz Marcinkowski
Affiliation:
MIM Fertility
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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
duckdb/duckdb-python のほかの issue
-
`read_json` accepts a list of paths at runtime but the type stub only allows a single path.対応中かも @aleks-drozy が 95 日前に担当しました。 オープンneeds triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
duckdb/duckdb-python#576 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Missing ROW_GROUPS_PER_FILE argument in write_parquet function対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンneeds triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
duckdb/duckdb-python#386 ·
メンテナーはふだん 1 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 66/100
duckdb/duckdb-python#737 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
duckdb/duckdb-python#736 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
duckdb/duckdb-python#733 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
duckdb/duckdb-python の issue をすべて見る
似ている issue
-
community enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
Hochfrequenz/sapgui.mcp#1039 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
didi/helixharness#18 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
dataforgoodfr/democracy-watch#46 · リアクション 1 件 ·