Skip to content

Stack overflow collecting PGO data on Windows #113655

Description

@mdboom

Bug report

Bug description:

During a PGO build on Windows on main (471aa75), a test in test_functools fails with a stack overflow.

Full log of build

PCbuild\build.bat --pgo
0:02:50 load avg: 0.35 [19/44] test_functools
Windows fatal exception: stack overflow

Thread 0x00002b38 (most recent call first):
  File "C:\actions-runner\_work\benchmarking\benchmarking\cpython\Lib\test\libregrtest\win_utils.py", line 43 in _update_load

Current thread 0x00000e3c (most recent call first):
  File "C:\actions-runner\_work\benchmarking\benchmarking\cpython\Lib\test\test_functools.py", line 1[875](https://github.com/faster-cpython/benchmarking/actions/runs/7367240496/job/20050307979#step:10:876) in fib
  File "C:\actions-runner\_work\benchmarking\benchmarking\cpython\Lib\test\test_functools.py", line 1875 in fib
  ...

C:\actions-runner\_work\benchmarking\benchmarking\cpython>"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe" "C:\actions-runner\_work\benchmarking\benchmarking\cpython\PCbuild\\pythoncore.vcxproj" /t:KillPython /nologo /v:m /clp:summary /p:Configuration=PGInstrument /p:Platform=x64 /p:KillPython=true 

  Killing any running python.exe instances...

C:\actions-runner\_work\benchmarking\benchmarking\cpython\PCbuild\pyproject.props(184,5): error : PGO run did not succeed (no python313!*.pgc files) and there is no data to merge [C:\actions-runner\_work\benchmarking\benchmarking\cpython\PCbuild\pythoncore.vcxproj]

Build FAILED.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    performancePerformance or resource usage
    on Jan 2, 2024
  2. self-assigned this
    on Jan 2, 2024
  3. gvanrossum commented on Jan 2, 2024

    @gvanrossum
    Member

    Trying to repro, I can't even manage to complete a PGO build (first step above).

  4. mdboom commented on Jan 2, 2024

    @mdboom
    ContributorAuthor

    It sounds like you are repro'ing (I probably wasn't clear enough). It fails during the PGO build while running the tests that generate PGO data.

    git bisect tells me the first bad commit is: 45e09f9 (which increased the recursion limit, which at least seems related).

  5. mdboom commented on Jan 2, 2024

    @mdboom
    ContributorAuthor

    It looks like 45e09f9 introduced the failing test, so it could just be that the test is incorrect (rather than a test going from passing to failing).

  6. gvanrossum commented on Jan 2, 2024

    @gvanrossum
    Member

    Ah, you're right, the output similar to yours scrolled off my screen. :-(

    You should be able to experiment with some of the numbers changed by the PR to see which one affects the Windows PGO build. The stack limit is definitely an ongoing discussion.

  7. mdboom commented on Jan 2, 2024

    @mdboom
    ContributorAuthor
  8. added a commit that references this issue on Jan 2, 2024
  9. gvanrossum commented on Jan 2, 2024

    @gvanrossum
    Member

    So it is crashing in this addition to test_functools.py:

        @support.skip_on_s390x
        @unittest.skipIf(support.is_wasi, "WASI has limited C stack")
        def test_lru_recursion(self):
    
            @self.module.lru_cache
            def fib(n):
                if n <= 1:
                    return n
                return fib(n-1) + fib(n-2)
    
            if not support.Py_DEBUG:
                with support.infinite_recursion():
                    fib(2500)
    

    My conclusion is that the increased default C recursion limit is too large for the platform and we hit a stack overflow. Maybe try setting Py_C_RECURSION_LIMIT to something smaller than 8000? (I am trying now with 4000.)

  10. mdboom commented on Jan 2, 2024

    @mdboom
    ContributorAuthor

    My conclusion is that the increased default C recursion limit is too large for the platform and we hit a stack overflow. Maybe try setting Py_C_RECURSION_LIMIT to something smaller than 8000? (I am trying now with 4000.)

    Yes -- my experimentation arrived at that too. 5,000 is too large, but 4,000 seems to work. See #113668.

  11. gvanrossum commented on Jan 2, 2024

    @gvanrossum
    Member

    Also, this docstring (deleted by that PR) suggests a possible cause:

        """Set a lower limit for tests that interact with infinite recursions
        (e.g test_ast.ASTHelpers_Test.test_recursion_direct) since on some
        debug windows builds, due to not enough functions being inlined the
        stack size might not handle the default recursion limit (1000). See
        bpo-11105 for details."""
    

    Maybe we are running into the inlining problem even in non-debug mode?

  12. 60 remaining items

  13. zooba commented on Feb 19, 2025

    @zooba
    Member

    Is there a plan to backport the fix to 3.12 and 3.13? Or do we need to keep the resource overallocation in those versions?

    I'd prefer to backport. Or at least trim the hardcoded limit to avoid crashing.

  14. reopened this on Feb 19, 2025
  15. encukou commented on Feb 24, 2025

    @encukou
    Member

    The fix uncovered unrelated issues. I don't think backporting it would be appropriate; definitely not for all platforms. It needs the full alpha/beta period.

  16. mowmanminer commented on Sep 27, 2025

    @mowmanminer
  17. Thyre commented on Jan 5, 2026

    @Thyre
  18. vstinner commented on Jan 6, 2026

    @vstinner
  19. hugovk commented on Jun 23, 2026

    @hugovk
    Member

    This has had the full 3.14 alpha/beta period plus RC and half a dozen bugfixes.

    Do we want to backport this, close it, or remove deferred-blocker?

  20. zooba commented on Jun 23, 2026

    @zooba
    Member

    I don't remember if the all the issues were resolved (I think it broke some Boost stuff?).

    As far as I'm aware, Python 3.12 and 3.13 will forever require 3-4x memory usage because of the temporary patch we put in to keep releasing. Since we've made it this far into their lifespans without major complaint, I guess it's fine to leave them patched that way.

  21. chris-eibl commented on Jun 24, 2026

    @chris-eibl
    Member

    Python 3.12 and 3.13 will forever require 3-4x memory usage

    I think only 3.12 is affected, since Revert extra stack reserve (commit 665b8f3) is tagged since v3.13.0a4?

  22. hugovk commented on Oct 2, 2026

    @hugovk
    Member

    Removing the deferred-blocker label as this hasn't delayed any releases, and 3.12 and 3.13 are both security-fix only with no Windows installers.

  23. encukou commented on Oct 2, 2026

    @encukou
    Member

    3.12 and 3.13 are both security-fix only

    That means a fix wouldn't be accepted to the remaining affected branches. I'll close.

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

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13only security fixesOS-windowsbuildThe build process and cross-buildperformancePerformance or resource usagetype-bugAn unexpected behavior, bug, or error

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions