Sitelet https://github.com/python/cpython/issues/93584
Skip to content

make altinstall for PGO is not parallel-safe #93584

Description

@tiran

Bug report

setup.py has a helper method add_multiarch_paths. The method creates a temporary file build/lib.{platform}/multiarch and unlinks it at the end of the function call. This is not parallel-safe.

PGO builds of Python use $(MAKE), so called recursive make. Recursive makes are considered harmful because the main make process has no understanding what the child make process is doing. With heavy parallel makes this can cause race conditions.

The combination of unsafe add_multiarch_paths(), recursive make and loooots of CPU cores can lead to build issues like #84461 (comment).

Possible workarounds

  1. Rewrite our Makefile to not use $(MAKE)
  2. Move CC -print-multiarch and dpkg-architecture ... -qDEB_HOST_MULTIARCH calls to configure.ac
  3. Fix _bootsubprocess.check_output() and add_multiarch_paths() to use a more safe tmp file

Option (3) is the simplest approach. Even tmpfile = os.path.join(self.build_temp, f'multiarch-{os.getpid()}') would be good enough to avoid file conflicts in parallel builds.

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    buildThe build process and cross-build
    3.11only security fixes
    3.12only security fixes
    on Jun 7, 2022
  2. self-assigned this
    on Jun 7, 2022
  3. tiran commented on Jun 7, 2022

    @tiran
    MemberAuthor

    My PR solved the race condition in add_multiarch_paths() but revealed another race condition later.

    @pablogsal 's problem is caused by the fact that PGO builds use recursive make. The sharedmods target and the profile-opt target run ./python setup.py build at the same time. setup.py is not designed to be parallel-safe.

  4. emmatyping commented on Jun 7, 2022

    @emmatyping
    Member

    Weird, I never hit a compilation failure after 2 hours of trying on my 32 core machine, maybe this is an edge case you can only hit with the macOS scheduler.

  5. tiran commented on Jun 7, 2022

    @tiran
    MemberAuthor

    Did you create a build with configure --enable-optimizations? The issue only occurs with PGO builds.

  6. emmatyping commented on Jun 7, 2022

    @emmatyping
    Member

    Yeah, I was running a script in a loop using the steps from Pablo's reproducer here: #84461 (comment)

    After 2 hours it still hadn't failed

  7. pablogsal commented on Jun 7, 2022

    @pablogsal
    Member

    Yeah, I was running a script in a loop using the steps from Pablo's reproducer here: #84461 (comment)

    After 2 hours it still hadn't failed

    That's odd. I have been able to reproduce in at least 3 systems, including Linux with arch Linux and RHEL7

  8. tiran commented on Jun 8, 2022

    @tiran
    MemberAuthor

    In comment #93589 (comment) @nascheme suggested to rename some of the targets to make the intention more clear. I like the idea, but I don't want to mix improvements with a release blocker fix.

  9. changed the title [-]setup.py add_multiarch_paths() is not parallel-safe with recursive make[/-] [+]make altinstall for PGO is not parallel-save[/+] on Jun 8, 2022
  10. added 3 commits that reference this issue on Jun 8, 2022
  11. changed the title [-]make altinstall for PGO is not parallel-save[/-] [+]make altinstall for PGO is not parallel-safe[/+] on Jun 15, 2022
  12. tiran commented on Jun 15, 2022

    @tiran
    MemberAuthor

    @pablogsal As far as I know this bug has been fixed by GH-93589.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesbuildThe build process and cross-buildrelease-blockertype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions