`put_async(Path)` opens files synchronously while holding the GIL

オープン
#809 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python, rust

調査の方向性

Start by tracing put_async() argument extraction for native Path inputs and the Rust async upload path; the issue names no source files or tests. Check how file opening and seek based size detection interact with cancellation and multipart selection. Done means slow opens do not block the event loop or hold the GIL, with the existing reader and upload behavior preserved.

索引モデルが issue の本文から書いたものです。

説明

Passing a pathlib.Path to obstore.put_async() opens the file during PyO3 argument extraction, before returning the awaitable. This happens synchronously while holding the Python GIL.

If opening the file stalls, it blocks the calling event loop. Moving the call to a Python worker thread does not fully address this: the file open still holds the GIL, preventing other Python threads from progressing.

Reproduction

On Unix, a named pipe provides a deterministic way to simulate a slow open. An external process supplies data after one second:

import asyncio
import os
import subprocess
import sys
import tempfile
from pathlib import Path

import obstore
from obstore.store import MemoryStore


async def main():
    with tempfile.TemporaryDirectory() as directory:
        source = Path(directory) / "source"
        os.mkfifo(source)

        writer = subprocess.Popen([
            sys.executable,
            "-c",
            """
import sys
import time

time.sleep(1)
with open(sys.argv[1], "wb") as output:
    output.write(b"hello")
""",
            str(source),
        ])

        async def heartbeat():
            while True:
                print("tick", flush=True)
                await asyncio.sleep(0.1)

        heartbeat_task = asyncio.create_task(heartbeat())
        try:
            await asyncio.sleep(0.1)
            await obstore.put_async(
                MemoryStore(),
                "destination",
                source,
                use_multipart=False,
            )
        finally:
            heartbeat_task.cancel()
            await asyncio.gather(heartbeat_task, return_exceptions=True)
            await asyncio.to_thread(writer.wait)


asyncio.run(main())

Observed: heartbeats stop while the file is opening.

Expected: local file preparation should not block the Python event loop or hold the GIL during blocking filesystem operations.

Possible fix

Defer opening native Path inputs until the Rust async operation runs, using tokio::task::spawn_blocking for opening and any seek-based size detection. Preserve the existing native reader and upload pipeline afterward.

A local prototype passes regression tests for event-loop responsiveness, cancellation during opening, and multipart selection. One observable behavior change is that file-opening errors would surface when awaiting the operation, rather than during the initial call.

If this fix is sound, I can open a PR with my local patch.

Reproduced with Obstore 0.11.1, CPython 3.14.7, macOS arm64.

主要言語
Python
スター
830
フォーク
45
平均マージ
7時間 53分
マージ済み PR(30日)
13

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

developmentseed/obstore のほかの issue

developmentseed/obstore の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。