Possible reference leak of the argument tuple in `FunctionCall()`
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 76/100
Hướng nghiên cứu
Bắt đầu trong src/map.cpp tại FunctionCall và xem xét các quy tắc ownership của CPython đối với PyTuple_Pack và PyObject_CallObject. Xác minh rằng tuple đối số được giải phóng sau cả các lần gọi thành công và thất bại, trong khi df_obj vẫn giữ nguyên cách xử lý ownership hiện có. Được xem là hoàn tất khi các lần gọi DuckDBPyRelation.map() lặp lại không còn làm rò rỉ tuple hoặc giữ lại DataFrame đầu vào.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happens?
FunctionCall() passes a newly created tuple directly to PyObject_CallObject():
File: src/map.cpp
Function: FunctionCall
auto *df_obj = PyObject_CallObject(function, PyTuple_Pack(1, in_df.ptr()));
PyTuple_Pack() returns a new reference, while PyObject_CallObject() does
not steal its args reference. Because the tuple is not stored in a local
variable, it is never passed to Py_DECREF().
As a result, every invocation leaks one tuple. The tuple also owns a reference
to in_df, so the input pandas DataFrame remains alive after FunctionCall()
returns. This occurs on both successful and failed calls.
The function is used during bind-time schema inference and query execution, so
the leak is reachable through ordinary DuckDBPyRelation.map() operations.
The handling of df_obj is unrelated and correct:
auto df = py::reinterpret_steal<py::object>(df_obj);
PyObject_CallObject() returns a new reference on success, which
reinterpret_steal() adopts.
To Reproduce
This issue can be confirmed directly from the reference ownership in
src/map.cpp.
In FunctionCall(), the argument tuple is created inline:
auto *df_obj = PyObject_CallObject(function, PyTuple_Pack(1, in_df.ptr()));
According to the CPython C API reference ownership rules:
PyTuple_Pack()returns a new reference.PyObject_CallObject()does not steal the reference passed asargs.- The tuple pointer is not stored, so there is no subsequent
Py_DECREF()for that new reference. - The tuple therefore leaks on every call and retains its reference to
in_df.
This issue is specific to the Python API and is not reproducible through plain
SQL in the DuckDB CLI.
OS:
x86_64
DuckDB Package Version:
latest version
Python Version:
3.12
Full Name:
Ksx
Affiliation:
SMU
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have not tested with any build
Did you include all relevant data sets for reproducing the issue?
No - Other reason (please specify in the issue body)
Did you include all code required to reproduce the issue?
- Yes, I have
Did you include all relevant configuration to reproduce the issue?
- Yes, I have
- Ngôn ngữ chính
- Python
- Star
- 186
- Fork
- 113
- Merge trung bình
- 22 giờ 45 phút
- Pull request đã merge (30 ngày)
- 14
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
-
needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
duckdb/duckdb-python#633 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
duckdb/duckdb-python#627 ·
-
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 · 3 bình luận ·
-
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 ·
-
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#622 ·
Tất cả issue của duckdb/duckdb-python
Issue tương tự
-
agent-ready documentation needs-triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
Add https://search.jeremyh.xyz/ Đang mởinstance instance add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
searxng/searx-instances#939 · 1 bình luận ·
-
area-deployment area-integrations triage:bot-seen
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 86/100