GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Torn reads of GC statistics from external process via get_gc_stats · Issue #155811 · python/cpython

Torn reads of GC statistics from external process via get_gc_stats #155811

New issue
Copy link
New issue
Copy link
Closed
Closed
Torn reads of GC statistics from external process via get_gc_stats#155811
Copy link
Labels
3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@sergey-miryanov
sergey-miryanov
opened on Aug 14, 2026
Issue body actions

Bug report

Bug description:

If an external tool sampling GC statistics does not pause the target process (and we designed get_gc_stats not to pause), it can read torn data under certain circumstances.

There are two distinct problems:

  1. Weakly ordered platforms: The stores of ts_start and ts_stop may be reordered by the CPU/optimizer. We need to add memory barriers to mitigate this.

  2. Large memcpy window: We are copying a sufficiently large memory region via memcpy. If two or more GC cycles occur during this copy, we can end up with inconsistent data spanning multiple GC states.

@maurycy has an idea to use a sequence counter for consistency checks — I think he should definitely give it a try.

cc @pablogsal

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-155811: Add a seqcount to gc_stats to prevent torn reads #155828
  • [3.15] gh-155811: Add a seqcount to gc_stats to prevent torn reads (GH-155828) #158829
Reacted by Maurycy Pawłowski-Wieroński

Activity

  1. sergey-miryanov
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Aug 14, 2026
  2. sergey-miryanov commented on Aug 14, 2026

    @sergey-miryanov
    sergey-miryanov
    on Aug 14, 2026
    ContributorAuthor
    More actions

    I don't think we should retry more than once if the GC stats read is inconsistent. Complex retry logic should be handled by the external tools.

    Reacted by Maurycy Pawłowski-Wieroński
  3. pablogsal
    added 2 commits that reference this issue on Oct 5, 2026

    pythongh-155811: Retry an inconsistent GC snapshot once

    577305e

    gh-155811: Add a seqcount to `gc_stats` to prevent torn reads (#155828)

    5fecd44
  4. maurycy commented on Oct 5, 2026

    @maurycy
    maurycy
    on Oct 5, 2026
    Contributor
    More actions

    @sergey-miryanov All good now? :)

  5. sergey-miryanov commented on Oct 5, 2026

    @sergey-miryanov
    sergey-miryanov
    on Oct 5, 2026
    ContributorAuthor
    More actions

    Since this is a bug fix, I think it should be backported.

    I don't think we'll get this into 3.15.0, so I'm perfectly fine with waiting for 3.15.1.

    cc @hugovk

  6. hugovk commented on Oct 5, 2026

    @hugovk
    hugovk
    on Oct 5, 2026
    Member
    More actions

    Yep, this can wait for .1

    • Core team: very little will be merged into the 3.15 branch between now and 3.15.0 final. Docs improvements always welcome.

    https://discuss.python.org/t/python-3-15-following-tradition-lets-have-a-surprise-rc3/109313

    Reacted by Maurycy Pawłowski-Wieroński and Sergey Miryanov
  7. pablogsal
    added a commit that references this issue on Oct 5, 2026

    [3.15] gh-155811: Add a seqcount to `gc_stats` to prevent torn reads (G…

    0281240
  8. sergey-miryanov
    closed this as completedon Oct 5, 2026
  9. pablogsal
    added a commit that references this issue on Oct 5, 2026

    Revert "[3.15] pythongh-155811: Add a seqcount to `gc_stats` to preve…

    693eccc
  10. Kronuz
    added 6 commits that reference this issue on Oct 5, 2026

    pythongh-146527, pythongh-155811: Backport out-of-process GC statisti…

    a9a6d3a

    pythongh-146527, pythongh-155811: Backport out-of-process GC statisti…

    5f652ff

    pythongh-146527, pythongh-155811: Backport out-of-process GC statisti…

    70b3c2d

    pythongh-146527, pythongh-155811: Backport out-of-process GC statisti…

    3453253

    pythongh-146527, pythongh-155811: Backport out-of-process GC statisti…

    c8d47d4

    pythongh-146527, pythongh-155811: Backport out-of-process GC statisti…

    7ecdc72
  11. sergey-miryanov
    reopened this on Oct 7, 2026
  12. hugovk
    closed this as completedon Oct 11, 2026
  13. sergey-miryanov commented on Oct 11, 2026

    @sergey-miryanov
    sergey-miryanov
    on Oct 11, 2026
    ContributorAuthor
    More actions

    @hugovk Backport was reverted in c49b3dc, so I reopened it. Do you mind I reopen it again? :)

  14. pablogsal
    added a commit that references this issue on Oct 11, 2026

    [3.15] Restore deferred backports for 3.15.1, including GH-158874 (#1…

    4ceb3fa
  15. hugovk commented on Oct 11, 2026

    @hugovk
    hugovk
    on Oct 11, 2026
    Member
    More actions

    Re-added in #158882?

    Reacted by Maurycy Pawłowski-Wieroński and Sergey Miryanov
    Reacted by Sergey Miryanov and Maurycy Pawłowski-Wieroński
  16. sergey-miryanov commented on Oct 11, 2026

    @sergey-miryanov
    sergey-miryanov
    on Oct 11, 2026
    ContributorAuthor
    More actions

    Yes, I missed that. Thanks!

    Reacted by Hugo van Kemenade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.