nanobind: leaked ... when a DuckDB type is referenced in overload signature and numpy is imported
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 203
- Fork
- 124
- Merge trung bình
- 13 giờ 36 phút
- Pull request đã merge (30 ngày)
- 61
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của duckdb/duckdb-python
-
`read_json` accepts a list of paths at runtime but the type stub only allows a single path.Có thể đã có người làm @aleks-drozy đã nhận 95 ngày trước. Đang mởneeds triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
duckdb/duckdb-python#576 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Missing ROW_GROUPS_PER_FILE argument in write_parquet functionCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởneeds triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
duckdb/duckdb-python#386 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
duckdb/duckdb-python#737 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
duckdb/duckdb-python#736 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
duckdb/duckdb-python#733 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của duckdb/duckdb-python
Issue tương tự
-
area/test type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Clodmony/starship-coop#70 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
punitarani/fli#270 ·
-
🐛 Bug 🔔 Pending processing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
jumpserver/jumpserver#17980 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
community enhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Claiming namespace `prodmetrics`Đang mởnamespace
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 60/100
EclipseFdn/open-vsx.org#15341 ·
Maintainer thường phản hồi trong vòng 1 ngày