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 — gh-116738: Make lzma module thread-safe by yoney · Pull Request #142947 · python/cpython

Conversation

@yoney

@yoney yoney commented Dec 18, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Make the attributes in lzma module thread-safe on the free-threading build. Attributes (check, eof, needs_input, unused_data) are now stored atomically or accessed via mutex-protected getters.

Even though the operations are protected by locks, the attributes exposed via PyMemberDef (check, eof, needs_input, unused_data) should still be updated atomically while holding the lock, or accessed via mutex‑protected getters, because they can be read without acquiring the lock.

This issue was not addressed in #140711. A small addition that repeatedly reads these attributes shows the issue under tsan build.

WARNING: ThreadSanitizer: data race (pid=2367860)
  Atomic read of size 1 at 0x7fdbc9506ee0 by thread T19:
    #0 _Py_atomic_load_char_relaxed /workspace/ft_lzma_tsan/./Include/cpython/pyatomic_gcc.h:311 (python+0x99e392) (BuildId: ce943d12d16f92ec125f1db1856a1617d3d75854)
    #1 PyMember_GetOne /workspace/ft_lzma_tsan/Python/structmember.c:37 (python+0x99e392)
    #2 member_get /workspace/ft_lzma_tsan/Objects/descrobject.c:180 (python+0x60f4d5) (BuildId: ce943d12d16f92ec125f1db1856a1617d3d75854)
...
...
...
Previous write of size 1 at 0x7fdbc9506ee0 by thread T11:
    #0 decompress /workspace/ft_lzma_tsan/./Modules/_lzmamodule.c:1067 (_lzma.cpython-315td-x86_64-linux-gnu.so+0x7256) (BuildId: 978a710f12e938f2fbc3233c01c40cf693105ef1)
    #1 _lzma_LZMADecompressor_decompress_impl /workspace/ft_lzma_tsan/./Modules/_lzmamodule.c:1139 (_lzma.cpython-315td-x86_64-linux-gnu.so+0x7256)
    #2 _lzma_LZMADecompressor_decompress /workspace/ft_lzma_tsan/./Modules/clinic/_lzmamodule.c.h:157 (_lzma.cpython-315td-x86_64-linux-gnu.so+0x7256)
...
...
...
SUMMARY: ThreadSanitizer: data race /workspace/ft_lzma_tsan/./Modules/_lzmamodule.c:1043 in decompress

cc: @mpage @colesbury

  • Issue: Audit all built-in modules for thread safety #116738

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

emmatyping reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@yoney
pythongh-116738: Make lzma module thread-safe
b422600
Make the attributes in lzma module thread-safe on the free-threading build.
Attributes (check, eof, needs_input, unused_data) are now stored atomically
or accessed via mutex-protected getters.
@bedevere-app bedevere-app Bot mentioned this pull request Dec 18, 2025
Audit all built-in modules for thread safety #116738
Open
@yoney
yoney marked this pull request as ready for review December 18, 2025 17:42
@bedevere-app bedevere-app Bot added the awaiting review label Dec 18, 2025
@colesbury
colesbury requested review from colesbury and emmatyping December 18, 2025 21:19
@colesbury colesbury added the topic-free-threading label Dec 18, 2025
ZeroIntensity
ZeroIntensity reviewed Dec 19, 2025
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2025-12-19-12-38-01.gh-issue-116738.iMt3Ol.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

emmatyping
emmatyping reviewed Dec 19, 2025
View reviewed changes
Comment thread Modules/_lzmamodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

yoney added 3 commits December 19, 2025 12:44
@yoney
Correct the NEWS section
2640d35
@yoney
Improve unused_data getter
637cc78
@yoney
Merge branch 'main' into ft_lzma_2
f26846f
@emmatyping

emmatyping commented Dec 23, 2025

Copy link
Copy Markdown
Member

Looks like jobs failed due to a spurious GitHub outage. I've re-run the failed jobs.

yoney reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Dec 28, 2025
View reviewed changes
Comment thread Modules/_lzmamodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@yoney @picnixz
Update Modules/_lzmamodule.c
bdc32fe
Co-authored-by: Bénédikt Tran <[email protected]>
colesbury
colesbury approved these changes Jan 5, 2026
View reviewed changes

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@emmatyping @picnixz - do you have any further feedback on the PR?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Jan 5, 2026
@colesbury
colesbury requested review from emmatyping and picnixz January 5, 2026 18:09
picnixz
picnixz approved these changes Jan 5, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2025-12-19-12-38-01.gh-issue-116738.iMt3Ol.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Modules/_lzmamodule.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

kumaraditya303
kumaraditya303 approved these changes Jan 13, 2026
View reviewed changes
@kumaraditya303
Merge branch 'main' into ft_lzma_2
ff7bf31
@kumaraditya303
kumaraditya303 enabled auto-merge (squash) January 13, 2026 13:36
@kumaraditya303
kumaraditya303 merged commit fca7fec into python:main Jan 13, 2026
47 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Jan 13, 2026
@yoney
yoney deleted the ft_lzma_2 branch January 27, 2026 17:07
@yoney yoney mentioned this pull request Jan 30, 2026
gh-116738: Align bz2 unused_data getter to lzma implementation #144351
Merged
thunder-coding pushed a commit to thunder-coding/cpython that referenced this pull request Feb 15, 2026
@yoney @thunder-coding
pythongh-116738: Make lzma module thread-safe (python#142947)
313c23b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@colesbury colesbury colesbury approved these changes
@picnixz picnixz picnixz approved these changes
@ZeroIntensity ZeroIntensity ZeroIntensity left review comments
@kumaraditya303 kumaraditya303 kumaraditya303 approved these changes
@emmatyping emmatyping Awaiting requested review from emmatyping

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic-free-threading

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@yoney @emmatyping @colesbury @picnixz @ZeroIntensity @kumaraditya303
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.