classification
Title: Race condition in "make regen-all" when running jobs in parallel
Type: Stage: resolved
Components: Build Versions: Python 3.10, Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, vstinner
Priority: normal Keywords: patch

Created on 2020-11-18 10:47 by vstinner, last changed 2020-11-18 17:23 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 23362 merged vstinner, 2020-11-18 11:15
PR 23367 merged vstinner, 2020-11-18 14:40
PR 23371 merged miss-islington, 2020-11-18 16:11
Messages (4)
msg381325 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-18 10:47
When building the Fedora package of Python 3.10, *sometimes* the "make regen-all" fail to build with errors like:
------------
/builddir/build/BUILD/Python-3.9.0/Modules/_weakref.c:131:5: error: '_WEAKREF_GETWEAKREFCOUNT_METHODDEF' undeclared here (not in a function)
  131 |     _WEAKREF_GETWEAKREFCOUNT_METHODDEF
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/builddir/build/BUILD/Python-3.9.0/Modules/_weakref.c:132:5: error: expected '}' before '_WEAKREF__REMOVE_DEAD_WEAKREF_METHODDEF'
  132 |     _WEAKREF__REMOVE_DEAD_WEAKREF_METHODDEF
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------

Example: https://src.fedoraproject.org/rpms/python3.9/pull-request/40

The _WEAKREF_GETWEAKREFCOUNT_METHODDEF macro is defined by Modules/clinic/_weakref.c.h which is included by Modules/_weakref.c (at line 13).

It seems like while Modules/_weakref.o was being built, Modules/clinic/_weakref.c.h was being generated "at the same time".

The "make regen-all" command runs "make clinic" and "make regen-importlib" targets:

* "make regen-importlib" builds Modules/_weakref.o from Modules/_weakref.c and  Modules/clinic/_weakref.c.h

* "make clinic" always rewrites "Modules/clinic/_weakref.c.h" file


On Fedora, packages are built using MAKEFLAGS="-j<N>" where <N> is a number, like "-j4". Since there is no dependency between "clinic" and "regen-importlib" targets, these two targets *can* be run in parallel.

It seems like "make clinic" always rewrites *all* generated files and the half of writes are *not* atomic.


Attached PR makes all writes of clinic.py atomic *and* also avoids modifying the file modification file if the content does not change, as done in other "make regen-all" targets (using Tools/scripts/update_file.py).
msg381348 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-18 14:36
New changeset 8fba9523cf08029dc2e280d9f48fdd57ab178c9d by Victor Stinner in branch 'master':
bpo-42398: Fix "make regen-all" race condition (GH-23362)
https://github.com/python/cpython/commit/8fba9523cf08029dc2e280d9f48fdd57ab178c9d
msg381355 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-18 16:11
New changeset c53c3f400050a7edc92ccb7285a6d7eeb4c37fd2 by Victor Stinner in branch '3.9':
bpo-42398: Fix "make regen-all" race condition (GH-23362) (GH-23367)
https://github.com/python/cpython/commit/c53c3f400050a7edc92ccb7285a6d7eeb4c37fd2
msg381356 - (view) Author: miss-islington (miss-islington) Date: 2020-11-18 16:29
New changeset 66dd5338a1ca98921c8e6c51228541ef8ed8076a by Miss Islington (bot) in branch '3.8':
bpo-42398: Fix "make regen-all" race condition (GH-23362) (GH-23367)
https://github.com/python/cpython/commit/66dd5338a1ca98921c8e6c51228541ef8ed8076a
History
Date User Action Args
2020-11-18 17:23:44vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-11-18 16:29:15miss-islingtonsetmessages: + msg381356
2020-11-18 16:11:23miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request22264
2020-11-18 16:11:17vstinnersetmessages: + msg381355
2020-11-18 14:40:32vstinnersetpull_requests: + pull_request22260
2020-11-18 14:36:35vstinnersetmessages: + msg381348
2020-11-18 11:15:46vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request22255
2020-11-18 10:47:58vstinnercreate