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-161769: Preserve errno across release thread-state attachment by Robolightning · Pull Request #161770 · python/cpython

Conversation

@Robolightning

@Robolightning Robolightning commented Nov 10, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Preserve the existing errno value across _PyThreadState_Attach() in release builds as well as debug builds. On a release free-threaded build, reattachment can change errno after a native wait, making valid directory EOF raise spurious EAGAIN.

The native change only removes the two Py_DEBUG conditionals around the existing save/restore. The regression now uses a 16-line method with four ordinary threads, GC and os.listdir, using the existing run_concurrently helper. No subinterpreter, FileFinder, JSON, ThreadPool or custom shutdown helper is needed.

The identical reduced test fails with errno 11 before the native fix and passes afterwards on native release free-threaded musl source builds of both main and 3.15. The complete test_os module then passes both tests on each corrected runtime, with natural GIL off. The earlier retained IO, GC, threading and import qualification covered 2,100 cases on 3.15 and 2,120 on main, with zero failures/errors and their original platform skips; the native patch has not changed. Upstream CI for aac344d completed successfully: all 48 jobs in the Tests workflow, the lint and label workflows, and all 56 check/status contexts were green when verified.

Fixes #161769. Includes a NEWS entry. No third-party module or installed SDK is changed.

AI assistance was used for investigation, patch/test preparation and this description. The before/after and standard-library results come from real native source builds.

  • Issue: Release free-threaded thread-state attachment can clobber errno and cause spurious directory I/O EAGAIN #161769

Sorry, something went wrong.

Uh oh!

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

All reactions
Robolightning added 2 commits November 10, 2026 19:42
@Robolightning
Preserve errno across thread-state attachment in release builds
0b9d037
Keep the existing _PyThreadState_Attach errno save/restore in release
builds as well as debug builds. A release free-threaded attachment can
wait for GC or critical-section resumption and change errno, causing valid
directory EOF and cold FileFinder operations to raise spurious EAGAIN.

Add a public directory/scandir/FileFinder regression under real child-local
GC, without native diagnostic modules or third-party code. The identical
test fails on current main 3.16 before the four-guard-line change and passes
afterwards. Original IO, GC, threading and import suites also pass on the
native musl release FT source build. No installed SDK is modified.
@Robolightning
pythongh-161769: Document errno preservation across thread-state atta…
452cc04
…chment
@Robolightning
Robolightning requested review from FFY00, ZeroIntensity and ericsnowcurrently as code owners November 10, 2026 18:18
@python-cla-bot

python-cla-bot Bot commented Nov 10, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot mentioned this pull request Nov 10, 2026
Release free-threaded thread-state attachment can clobber errno and cause spurious directory I/O EAGAIN #161769
Open
@bedevere-app bedevere-app Bot added the awaiting review label Nov 10, 2026
Robolightning added 2 commits November 10, 2026 21:28
@Robolightning
pythongh-161769: Render errno as a literal in NEWS
87ad37c
Correct the new NEWS reference rejected by the actual Docs job. Keep the
qualified native source and public regression unchanged.
@Robolightning
pythongh-161769: Use standard long timeouts for concurrent regression
920a86d
Actual upstream TSanFT reached the new hard30second worker-join timeout
before the scanners finished. Use test.support.LONG_TIMEOUT as recommended
for slow/instrumented buildbots. Keep all scan/GC workload and assertions.
Re-prove the identical adjusted test on both current3.15 andmain native
release FT cores: actual BlockingIOError before, PASS after unchanged errno
fix. Original failing CI log and native loaded-library hashes are retained.
@NekoAsakura NekoAsakura added the AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor label Nov 10, 2026
@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

Thank you for your interest in contributing to Python. This is a community-driven project, and we want it to be a welcoming place to learn and collaborate.

Contributors are responsible for reviewing and understanding what they submit, checking its claims, and being able to explain changes in their own words. This helps reviewers focus on the contribution and leaves more time to support other contributors.

This contribution appears to have been authored with AI assistance. Please explain your contribution in your own words and describe how you checked its correctness.

Please read our guidelines for using AI tools.

All reactions

Sorry, something went wrong.

Uh oh!

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

@NekoAsakura

NekoAsakura commented Nov 10, 2026

Copy link
Copy Markdown
Member

I can only reproduce this on musl; elsewhere the new test passes without the fix. Please explain why and make sure your changes are minimal and focused.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Robolightning
pythongh-161769: Focus errno regression on ordinary threads and GC
aac344d
Replace the directory/SI lifecycle helper with one public listdir test
using the existing run_concurrently helper. Four ordinary threads each
collect GC and check a real directory. No FileFinder, JSON, subinterpreters,
ThreadPool, custom stop/barrier or deadline logic is needed.

The exact smaller test reproduced BlockingIOError errno11 before and
passed after the unchanged native errno fix on both main and3.15 native
Release FT musl cores. The existing strerror test remains unchanged and
the full test_os module passes on both corrected runtimes.
@Robolightning ChatGPT Codex Connector

Robolightning commented Nov 11, 2026

Copy link
Copy Markdown
Author

AI-assisted technical explanation, posted at the author's request.

musl’s blocking semaphore path can return success while leaving errno set to EAGAIN: sem_trywait sets it when empty, and sem_timedwait, also used by sem_wait, can subsequently succeed without restoring the incoming value. A separate valid POSIX semaphore example returned 0 with errno 11 on musl 1.2.6; the identical program returned 0 with errno 0 on glibc. This is an observed libc difference, not a claim that glibc must always preserve errno.

In CPython, reattachment can park during GC and reach _PySemaphore_Wait. os.listdir checks errno after Py_END_ALLOW_THREADS, so reattachment can turn a successful readdir EOF into a spurious error. Debug builds already save/restore errno here; the native fix remains just the removal of four conditional-compilation lines.

The regression is now a 16-line method in aac344d, using four ordinary threads, GC, os.listdir, and the existing run_concurrently helper. The identical reduced test genuinely failed with errno 11 before and passed after the unchanged fix on both main and 3.15 native release free-threaded musl builds, once per phase, with mapped-library hashes checked. The full test_os module then passed both tests on each corrected runtime. This also explains why a passing pre-fix run on another libc does not rule out the bug.

All reactions

Sorry, something went wrong.

Uh oh!

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

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

Reviewers

@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ZeroIntensity ZeroIntensity Awaiting requested review from ZeroIntensity ZeroIntensity is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner

Uh oh!

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

Assignees

No one assigned

Labels

AI-needs-explanation AI-assisted work that needs further explanation and follow up from the contributor awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Release free-threaded thread-state attachment can clobber errno and cause spurious directory I/O EAGAIN

Uh oh!

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

2 participants

@Robolightning @NekoAsakura
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.