python / python/cpython

`python -m asyncio ps` fails if any task name is longer than 255 characters

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

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

stdlib topic-asyncio type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

One task name longer than 255 characters makes python -m asyncio ps fail for the whole process. The length limit is treated as a validity check instead of a cap.

Repro:

  import asyncio
  import os
  from _remote_debugging import RemoteUnwinder

  async def main():
      asyncio.create_task(asyncio.sleep(10), name='x' * 256)
      await asyncio.sleep(0)
      print(RemoteUnwinder(os.getpid()).get_all_awaited_by())

  asyncio.run(main())

Actually:

  Traceback (most recent call last):
    File "/Users/timofeiivankov/cpython/repro.py", line 10, in <module>
      asyncio.run(main())
      ~~~~~~~~~~~^^^^^^^^
    File "/Users/timofeiivankov/cpython/Lib/asyncio/runners.py", line 205, in run
      return runner.run(main)
             ~~~~~~~~~~^^^^^^
    File "/Users/timofeiivankov/cpython/Lib/asyncio/runners.py", line 128, in run
      return self._loop.run_until_complete(task)
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
    File "/Users/timofeiivankov/cpython/Lib/asyncio/base_events.py", line 725, in run_until_complete
      return future.result()
             ~~~~~~~~~~~~~^^
    File "/Users/timofeiivankov/cpython/repro.py", line 8, in main
      print(RemoteUnwinder(os.getpid()).get_all_awaited_by())
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  RuntimeError: Invalid string length (256) at 0x101493800

Expected: the call returns and the long name comes back truncated:

[AwaitedInfo(thread_id=21170325, awaited_by=[
  TaskInfo(task_id=4312485712, task_name='Task-1', ...),
  TaskInfo(task_id=4312485232, task_name='xxx…' (truncated to 255), ...)])]

Proposed fix: Truncate to the limit instead of raising in object_reading.c

I have a fix ready for that

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-157790

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

object_reading.c から始め、提供されている asyncio のタスク名の例を使って、python -m asyncio ps または示されている RemoteUnwinder の呼び出しで失敗を再現します。タスク名が 255 文字を超えていても呼び出しが成功し、返される名前が 255 文字に切り詰められれば完了です;すでに進行中の作業については、リンクされている PR gh-157790 を確認してください。

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

評価

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

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

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