python / python/cpython

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

未关闭
#157,788 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 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 摘要。