python / python/cpython

Build failure: install race condition

未关闭
#102,007 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

build type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Bug report

The generated Makefile for Python 3.11 has a race condition in its install target.

So far it triggers easiest with GNU Make 4.4 (I think they distribute more tasks breadth first instead of depth first compared to v4.3)

In short, this is a reproducer of the problem:

LIBDIR := $(CURDIR)/lib
INSTALL := /usr/bin/install -c

all: a b

a b:
	@for i in $(LIBDIR); do \
		if test ! -d $$i; then \
			echo "Creating directory $$i"; \
			$(INSTALL) -d -m 755 $$i; \
		else true; \
		fi \
	done

causing a race as follows:

% make -j2
Creating directory /private/var/folders/33/7njsb0_50dl7hnkr58nbnpb00000gn/T/tmp.TOdJ6wpw/lib
Creating directory /private/var/folders/33/7njsb0_50dl7hnkr58nbnpb00000gn/T/tmp.TOdJ6wpw/lib
install: mkdir /private/var/folders/33/7njsb0_50dl7hnkr58nbnpb00000gn/T/tmp.TOdJ6wpw/lib: File exists
make: *** [a] Error 71

This happens exactly in Python during make install -j$(nproc) as the commoninstall target has the prereqs altbininstall libinstall (among others) which both have a shell script loop over some directories they wanna make, and in particular it has:

altbininstall: $(BUILDPYTHON)
	@for i in $(BINDIR) $(LIBDIR); \
		... like example above (if dir not exists, run install)

libinstall: all $(srcdir)/Modules/xxmodule.c
	@for i in $(SCRIPTDIR) $(LIBDEST); \
		... like example above (if dir not exists, run install)

where SCRIPTDIR and LIBDIR in my case both point to <prefix>/lib.

Your environment

Python 3.11
GNU Make 4.4
macOS Ventura M1

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先使用提供的 Makefile 和 make -j2 重现失败,然后检查为 commoninstallaltbininstalllibinstall 生成的安装规则。当并行执行 make install 时创建共享目录不再发生竞争(包括在 Python 3.11 上使用 GNU Make 4.4 时),修复就完成了。

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

评估

技术栈
python
领域
build-system
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

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