[Bug] RPC tracker TCPEventHandler._init_conn omits return after close() and PriorityScheduler has unlocked list/heap races

未关闭
#21,084 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 3 天内回复

@Nanmur 已经在做这个了。

开始于 2026年11月29日。

  • #21092 来自 @Nanmur —— 未关闭
  • #21093 来自 @Nanmur —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

Start in python/tvm/rpc/tracker.py at TCPEventHandler._init_conn() and PriorityScheduler (request(), _schedule(), put(), remove(), and summary()). Read the surrounding tracker code and existing tests for RPC handshakes and scheduler behavior. Done when malformed handshakes stop cleanly and concurrent scheduler operations no longer race; add or run focused tests for both cases.

由索引模型根据 Issue 内容生成。

描述

needs-triage type: bug
Summary

In python/tvm/rpc/tracker.py:

  1. TCPEventHandler._init_conn() (tracker.py:201-212): Calls self.close() on invalid handshake length (len(message) != 4) and invalid magic without returning:
    if len(message) != 4:
        logger.warning("Invalid connection from %s", self.name())
        self.close()
    magic = struct.unpack("<i", message)[0]
    if magic != RPC_TRACKER_MAGIC:
        logger.warning("Invalid magic from %s", self.name())
        self.close()
    self.write_message(struct.pack("<i", RPC_TRACKER_MAGIC), binary=True)
    
    Non-4-byte payloads fall through to unhandled struct.error (not caught by TCPHandler._update_read, which only catches OSError), and invalid 4-byte magics fall through to write_message on a closed socket.
  2. PriorityScheduler (tracker.py:132-170): Acquires self._lock only around heapq.heappush in request() (lines 157-159), leaving _schedule(), put(), remove(), and summary() completely unlocked and racing on self._values and self._requests.
Affected Location
  • Repository: apache/tvm (main, python/tvm/rpc/tracker.py:132-170,201-212)
Minimal Standalone Reproduction
  • _init_conn(b"GET / HTTP/1.1") raises struct.error: unpack requires a buffer of 4 bytes.
  • _init_conn(b"BAD!") calls close() then write_message -> OSError: socket is already closed.
  • Concurrent threads calling PriorityScheduler.put(), request(), and remove() trigger ValueError: list.remove(x): x not in list / IndexError: pop from empty list.
Suggested Fix
  1. Add return after both self.close() calls in _init_conn().
  2. Protect put(), request(), remove(), summary(), and _schedule() with self._lock (using threading.RLock or releasing/avoiding re-entrant callbacks while mutating scheduler state).
主要语言
Python
星标
13.9k
派生
4.1k
平均合并
4 天 22 小时
30 天内合并 PR
22

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/tvm 的其他 Issue

查看 apache/tvm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。