Leaked instances of DuckDBPyType since 2.0
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
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 内容生成。
描述
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 分钟
- 30 天内合并 PR
- 61
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 于 96 天前认领。 未关闭needs triage
难度 2/5 1-3 小时 新手友好度 78/100
duckdb/duckdb-python#576 · 1 条评论 ·
维护者通常 1 天内回复
-
Missing ROW_GROUPS_PER_FILE argument in write_parquet function可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭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
难度 3/5 1-2 天 新手友好度 68/100
duckdb/duckdb-python#733 · 2 条评论 ·
维护者通常 1 天内回复
-
nanobind: leaked ... when a DuckDB type is referenced in overload signature and numpy is imported未关闭needs triage
难度 4/5 3-5 天 新手友好度 25/100
duckdb/duckdb-python#732 · 5 条评论 · 3 个 reaction ·
维护者通常 1 天内回复
查看 duckdb/duckdb-python 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
Textualize/textual#6753 · 1 条评论 ·
-
priority:low size:small
难度 2/5 1-3 小时 新手友好度 70/100
RonaldHensbergen/composable-data-stack#1177 ·
维护者通常 1 天内回复
-
Use registered media types for HDF5 and NetCDF, and stop claiming media_type must be IANA-registered未关闭documentation metadata
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复
-
check-typing: ty 0.0.98+ fails on the renamed rule `unresolved-import` (now `import-not-found`)可能已有人在做 @oberstet 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 91/100
crossbario/cfxdb#145 ·