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 — Builtin zip method is not safe under free-threading · Issue #123271 · python/cpython

Builtin zip method is not safe under free-threading #123271

New issue
Copy link
New issue
Copy link
Closed
Closed
Builtin zip method is not safe under free-threading#123271
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@eendebakpt
eendebakpt
opened on Aug 23, 2024
Issue body actions

Bug report

Bug description:

A common optimization technique (used in zip_next) for methods generating tuples is to keep an internal reference to the returned tuple and when the method is called again check whether the internal tuple has reference count 1. If the refcount is one, the tuple can be re-used. Under the free-threading build this is not safe: after the check on the reference count another thread can perform the same check and also re-use the tuple. This can lead to a double decref on the items of the tuple replaced and a double incref (memory leak) on the items of the tuple being set.

Some options to address this:

  • Stop the internal tracking of the tuple. This affects performance of zip when the tuple can be re-used
  • Lock the entire zip object during a call to zip_next. This is expensive, also for the single-threaded case.
  • Use an atomic "check refcount equals one and conditionally increment" method. This could be less expensive than locking the entire object, but maybe this method is not available or almost as expensive as locking the object.

A minimal example reproducing the issue is added as a test in #123272. It shows the issue when executed with a free-threading debug build.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Windows

Linked PRs

  • gh-123271: Make builtin zip method safe under free-threading #123272

Activity

  1. eendebakpt
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 23, 2024
  2. picnixz
    added this to Zipfile issues 📦 and removed this from Zipfile issues 📦on Aug 23, 2024
  3. picnixz commented on Aug 23, 2024

    @picnixz
    picnixz
    on Aug 23, 2024
    Member
    More actions

    (Wrong zip, my bad)

  4. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Aug 23, 2024
  5. Eclips4
    added
    topic-free-threading
    on Aug 24, 2024
  6. colesbury
    added a commit that references this issue on Aug 27, 2024

    gh-123271: Make builtin zip method safe under free-threading (#123272)

    7e38e67
  7. colesbury
    closed this as completedon Aug 27, 2024
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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-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.