nanobind: leaked ... when a DuckDB type is referenced in overload signature and numpy is imported
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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
- Vorherrschende Sprache
- Python
- Sterne
- 203
- Forks
- 124
- Ø Merge
- 13 Std. 36 Min.
- Gemergte PRs (30 T.)
- 61
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus duckdb/duckdb-python
-
`read_json` accepts a list of paths at runtime but the type stub only allows a single path.Evtl. vergeben @aleks-drozy hat das vor 97 Tagen übernommen. Offenneeds triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
duckdb/duckdb-python#576 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Missing ROW_GROUPS_PER_FILE argument in write_parquet functionEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offenneeds triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
duckdb/duckdb-python#386 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 66/100
duckdb/duckdb-python#737 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs triage
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
duckdb/duckdb-python#736 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs triage
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
duckdb/duckdb-python#733 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in duckdb/duckdb-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
aws-samples/sample-per-model-bedrock#795 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
Pretalx reports older version to be the latest release than what is actually installed and availableOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
micropython/micropython#19906 ·
Maintainer antworten meist innerhalb von 1 Tag