Exit waits for a daemon thread's stalled HTTP read since 2.0.1 (2 minutes by default), then can abort
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Start from the exit hook added in #709 in duckdb-python's Python/C++ binding code and trace how it waits on a still-running query result at interpreter shutdown. Run the issue's repro.py with duckdb 2.0.1 and http_timeout=5 to observe the ~20 s delay, then compare against 2.0.0. Done means the process exits soon after the main thread returns, without waiting for the stalled HTTP read and without aborting.
索引モデルが issue の本文から書いたものです。
説明
What happens?
Since 2.0.1, a process whose daemon thread is inside a query blocked on an HTTP read that never gets an answer does not exit when the main thread returns. The exit hook added in #709 waits for the read to fail, which takes http_timeout × (http_retries + 1): 30 s × 4 = about 2 minutes with the defaults. When the read then fails, the error returns into the finalizing interpreter and the process sometimes aborts with a core dump:
- Python 3.12:
terminate called after throwing an instance of ''/FATAL: exception not rethrown - Python 3.13:
Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stderr>'> at interpreter shutdown, possibly due to daemon threads
With 2.0.0 the same script exits about 1 second after the main thread returns, with status 0.
The wait follows http_timeout: 20 s at SET http_timeout = 5, 40 s at 10, 120 s at the default 30. The server sees the GET retried every http_timeout until the retries run out. #709 interrupts a running query before closing its result, but the interrupt does not reach a task blocked in an HTTP read, so the close waits for the task.
The script only blocks if the stall comes during execution. When the server never answers at all, read_text blocks in the HEAD at bind time, before a result exists, and 2.0.1 exits at once. The reproducer answers the HEAD and stalls the GET.
To Reproduce
repro.py: a local HTTP server answers HEAD and never answers GET; a daemon thread reads from it with read_text; the main thread returns after a second.
# A daemon thread's query waits on an HTTP server that never answers its GET; the main thread returns.
# Usage: python repro.py [http_timeout_seconds]
import socket
import sys
import threading
import time
import duckdb
held = []
def handle(conn):
# Answer HEAD, so the file opens; accept the GET that reads it and never answer.
held.append(conn)
while conn.recv(65536).startswith(b"HEAD"):
conn.sendall(b"HTTP/1.1 200 OK\r\nContent-Length: 1000000\r\nAccept-Ranges: bytes\r\n\r\n")
def serve(server):
while True:
threading.Thread(target=handle, args=(server.accept()[0],), daemon=True).start()
server = socket.create_server(("127.0.0.1", 0))
threading.Thread(target=serve, args=(server,), daemon=True).start()
con = duckdb.connect()
con.execute("INSTALL httpfs; LOAD httpfs") # INSTALL downloads httpfs the first time
if len(sys.argv) > 1:
con.execute(f"SET http_timeout = {sys.argv[1]}")
url = f"http://127.0.0.1:{server.getsockname()[1]}/x.txt"
threading.Thread(target=lambda: con.sql(f"SELECT * FROM read_text('{url}')").fetchall(), daemon=True).start()
time.sleep(1)
print(f"duckdb {duckdb.__version__}, Python {sys.version.split()[0]}: main thread returns", flush=True)
uv run --with duckdb==2.0.1 python repro.py # default http_timeout: about 2 minutes
uv run --with duckdb==2.0.1 python repro.py 5 # about 20 s
uv run --with duckdb==2.0.0 python repro.py 5 # about 1 s
Linux x86_64, time from start to exit. The 2.0.0 runs also print nanobind's leak report on stderr.
| duckdb | Python | http_timeout |
runs | time to exit | exit status |
|---|---|---|---|---|---|
| 2.0.0 | 3.13.18 | default (30) | 6 | 1.1–1.2 s | 0 ×6 |
| 2.0.0 | 3.13.18 | 5 | 6 | 1.1–1.2 s | 0 ×6 |
| 2.0.0 | 3.12.3 / 3.14.10 | default (30) | 3 + 3 | 1.6 s | 0 ×6 |
| 2.0.1 | 3.13.18 | default (30) | 3 | 120.7–123.3 s | 0 ×2, abort (134) ×1 |
| 2.0.1 | 3.13.18 | 10 | 6 | 40.5–41.7 s | 0 ×6 |
| 2.0.1 | 3.13.18 | 5 | 9 | 21.2–23.6 s (one run 6.2 s) | 0 ×6, abort (134) ×3 |
| 2.0.1 | 3.12.3 | 5 | 4 | 20.7–22.1 s | 0 ×2, abort (134) ×2 |
| 2.0.1 | 3.14.10 | 5 | 4 | 21.0–22.0 s (one run 2.6 s) | 0 ×4 |
| 2.1.0.dev2611161157 | 3.13.18 | 5 | 6 | 21.2–23.8 s (one run 5.4 s) | 0 ×4, abort (134) ×2 |
Output of an aborted run (2.0.1, Python 3.12; exit status 134, core dumped):
duckdb 2.0.1, Python 3.12.3: main thread returns
terminate called after throwing an instance of ''
FATAL: exception not rethrown
Output of an aborted run (2.0.1, Python 3.13; exit status 134, core dumped):
duckdb 2.0.1, Python 3.13.18: main thread returns
Exception in thread Thread-2 (<lambda>):
Fatal Python error: _enter_buffered_busy: could not acquire lock for <_io.BufferedWriter name='<stderr>'> at interpreter shutdown, possibly due to daemon threads
Python runtime state: finalizing (tstate=0x00000000013ab820)
Current thread 0x000075cd5d2df740 (most recent call first):
<no Python frame>
The thread catching duckdb.Error itself does not avoid the wait: 4 runs on 2.0.1 / Python 3.13 at http_timeout = 5 took 20.7–21.8 s, all with status 0.
Expected: the process exits soon after the main thread returns, as with 2.0.0. A daemon thread's query should not hold up the exit.
Actual: the exit waits for the stalled request to fail (about 2 minutes with the defaults), and the process sometimes aborts once it does.
Suggestion: bound the exit hook's wait for a result whose query is still running (as #709 already does for taking the claim), or skip such a result, rather than waiting for a task that no interrupt reaches.
OS:
Linux x86_64
DuckDB Package Version:
2.0.1 (also 2.1.0.dev2611161157 from PyPI; 2.0.0 is not affected)
Python Version:
3.12.3, 3.13.18, 3.14.10
Full Name:
Chris O'Hara
Affiliation:
Bedrock Robotics
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a nightly build
Did you include all relevant data sets for reproducing the issue?
Not applicable - the reproduction does not require a data set
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
- 主要言語
- Python
- スター
- 206
- フォーク
- 126
- 平均マージ
- 20時間 18分
- マージ済み PR(30日)
- 36
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
duckdb/duckdb-python のほかの issue
-
needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
duckdb/duckdb-python#752 ·
メンテナーはふだん 1 日以内に返信
-
`read_json` accepts a list of paths at runtime but the type stub only allows a single path.対応中かも @aleks-drozy が 118 日前に担当しました。 オープン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 日以内に返信
-
import duckdb fails with 'Encountered an error while initializing the extension' when sys.modules has no __main__ (DetectEnvironment imports __main__ unconditionally)対応中かも @chouaibmouidis-py が 2 日前に担当しました。 オープン
難易度 3/5 半日 初心者へのやさしさ 68/100
duckdb/duckdb-python#795 ·
メンテナーはふだん 1 日以内に返信
-
needs triage
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
duckdb/duckdb-python#768 ·
メンテナーはふだん 1 日以内に返信
duckdb/duckdb-python の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
can4hou6joeng4/boss-agent-cli#3290 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 94/100
vllm-project/vllm#70568 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
exa-studio/ApiVault#338 ·
-
perf: the model list request spends over a third of its time converting data that is already JSONオープンbug confirmed issue
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
open-webui/open-webui#35211 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信