python / python/cpython

Build failure: install race condition

Open
#102,007 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with the provided Makefile and make -j2, then inspect the generated install rules for commoninstall, altbininstall, and libinstall. The fix is done when parallel make install no longer races while creating shared directories, including with GNU Make 4.4 on Python 3.11.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.