[Bug] RPC server _serving() skips os.chdir(old_cwd) and sock.close() when worker exits non-zero, leaving server in deleted CWD

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

维护者通常 3 天内回复

@Anurag1428 已经在做这个了。

开始于 2026年11月29日。

  • #21085 来自 @Anurag1428 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
python
领域
backend

调研方向

Read python/tvm/rpc/server.py around _serving() lines 138–178, then inspect the RPC server tests that exercise worker failures and timeouts. Reproduce a worker exit with a nonzero code and check whether the process restores its working directory and closes the socket; done means cleanup also runs on failure and the next session can be served.

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

描述

needs-triage type: bug
Summary

In python/tvm/rpc/server.py:138-178, _serving() creates a temporary directory work_path, changes into it via old_cwd = os.getcwd(); os.chdir(work_path.path), and does not wrap the body in try ... finally:

old_cwd = os.getcwd()
os.chdir(work_path.path)
...
elif server_proc.exitcode != 0:
    raise RuntimeError(...)

logger.info(f"finish serving {addr}")
os.chdir(old_cwd)
work_path.remove()
sock.close()

When the child worker process exits non-zero (e.g., segfault/abort), raise RuntimeError(...) skips os.chdir(old_cwd), work_path.remove(), and sock.close(). When work_path (TempDirectory) is garbage-collected, TempDirectory.__del__ deletes work_path.path — the parent server's current working directory — causing os.getcwd() on the next _serving() call to fail permanently with FileNotFoundError while leaking the client socket FD.

Affected Location
  • Repository: apache/tvm (main, python/tvm/rpc/server.py:138-178)
Minimal Standalone Reproduction

Calling _serving() when the worker exits with code 139, triggering gc.collect(), and accepting a second session:

  • First session raises RuntimeError: Child process ... exited unsuccessfully with error code 139 and leaves s1.fileno() >= 0 (leaked FD).
  • os.getcwd() and the next _serving() call immediately fail with FileNotFoundError: [Errno 2] No such file or directory.
Suggested Fix

Wrap lines 142-177 in try: ... finally: os.chdir(old_cwd); work_path.remove(); sock.close(), and join() server_proc after terminate() on timeout.

主要语言
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 摘要。