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 — [3.13] gh-150157: add critical section for `PyDict_Next` in `_pickle.c` by KowalskiThomas · Pull Request #150951 · python/cpython

Conversation

@KowalskiThomas

@KowalskiThomas KowalskiThomas commented Jun 5, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Backport of #150158 to 3.13

Fixes #150157.

  • Issue: Missing critical section for PyDict_Next in _pickle.c #150157

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot mentioned this pull request Jun 5, 2026
Missing critical section for PyDict_Next in _pickle.c #150157
Closed
@KowalskiThomas
KowalskiThomas force-pushed the kowalski/fix-critical-section-for-pydict_next-in-_pickle-c branch from d5290a5 to 42d3ef5 Compare June 5, 2026 09:58
@KowalskiThomas KowalskiThomas changed the title gh-150157: add critical section for PyDict_Next in _pickle.c gh-150157: add critical section for PyDict_Next in _pickle.c [backport 3.13] Jun 5, 2026
@KowalskiThomas KowalskiThomas changed the title gh-150157: add critical section for PyDict_Next in _pickle.c [backport 3.13] [3.13] gh-150157: add critical section for PyDict_Next in _pickle.c Jun 5, 2026
@KowalskiThomas KowalskiThomas mentioned this pull request Jun 5, 2026
gh-150157: fix: critical section for PyDict_Next in _pickle.c #150158
Merged
@read-the-docs-community

read-the-docs-community Bot commented Jun 5, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33006727 | 📁 Comparing afd0746 against main (2f064fb)

  🔍 Preview build  

456 files changed · ± 417 modified · - 39 deleted

± Modified

  • about.html
  • bugs.html
  • copyright.html
  • glossary.html
  • index.html
  • license.html
  • py-modindex.html
  • c-api/allocation.html
  • c-api/apiabiversion.html
  • c-api/arg.html
  • and 407 more...

- Deleted

  • improve-page-nojs.html
  • improve-page.html
  • _static/tachyon-example-flamegraph.html
  • _static/tachyon-example-heatmap.html
  • c-api/extension-modules.html
  • c-api/interp-lifecycle.html
  • c-api/lifecycle.html
  • c-api/profiling.html
  • c-api/sentinel.html
  • c-api/slots.html
  • and 29 more...
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jun 5, 2026

Copy link
Copy Markdown
Member

Something is wrong with the change. Example on the Windows CI:

test_global_lookup_error (test.test_pickle.CPicklingErrorTests.test_global_lookup_error) ...
Windows fatal exception: access violation

Current thread 0x00000f90 (most recent call first):
  File "D:\a\cpython\cpython\Lib\test\test_pickle.py", line 66 in dumps
  File "D:\a\cpython\cpython\Lib\test\pickletester.py", line 1850 in test_global_lookup_error
KowalskiThomas reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

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

@KowalskiThomas
fix: critical section for PyDict_Next in _pickle.c
afd0746
@KowalskiThomas
KowalskiThomas force-pushed the kowalski/fix-critical-section-for-pydict_next-in-_pickle-c branch from 42d3ef5 to afd0746 Compare June 5, 2026 11:52
@KowalskiThomas

KowalskiThomas commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Indeed, I got a bit too trigger-happy on the Py_DECREF and so sometimes modules was being dec-ref'd twice. Should be good now, I'll keep an eye on the CI.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jun 5, 2026

Copy link
Copy Markdown
Member

Try to avoid force push, it makes reviews harder to follow in GitHub.

KowalskiThomas 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.

@KowalskiThomas

KowalskiThomas commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Noted, I'll keep that in mind for the future.

All reactions

Sorry, something went wrong.

Uh oh!

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

@KowalskiThomas
KowalskiThomas marked this pull request as ready for review June 5, 2026 12:12
@bedevere-app bedevere-app Bot added the awaiting review label Jun 5, 2026
@KowalskiThomas

KowalskiThomas commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

CI is green now, thanks for the heads up! :)

All reactions

Sorry, something went wrong.

Uh oh!

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

vstinner
vstinner reviewed Jun 5, 2026
View reviewed changes
Comment thread Modules/_pickle.c
int error = 0;
i = 0;
Py_BEGIN_CRITICAL_SECTION(modules);
while (PyDict_Next(modules, &i, &module_name, &module)) {

@vstinner vstinner Jun 5, 2026

Copy link
Copy Markdown
Member

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.

In the main branch, the code creates explicitly strong references:

                Py_INCREF(module_name);
                Py_INCREF(module);

@serhiy-storchaka: You added these Py_INCREF() calls in commit 1bb955a. Do you think that we should backport them?

It seems like _checkmodule() can call arbitrary Python code, especially in getattribute(). So it would be safer to hold strong references, no?

Sorry, something went wrong.

Uh oh!

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

All reactions
@serhiy-storchaka

serhiy-storchaka commented Jun 5, 2026

Copy link
Copy Markdown
Member

There was no critical section in that code, so the original issue is not applicable here. This code is just not free-threading ready. Adding a critical section would be a new feature.

Adding Py_INCREFs after PyDict_CheckExact() is a different story. Yes, there is a possible use-after-free bug reproducible without free-threading.

KowalskiThomas 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.

@KowalskiThomas

KowalskiThomas commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

I see -- if I understand correctly there should never have been a 3.13 backport because the function wasn't supposed to support free-threading in 3.13, right?

Do you want me to change the PR to remove the current changes and make the function hold strong references or should this go to a different PR altogether (and this one be closed)? (I feel like the usual practice on CPython would be the latter, but asking anyway.)

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka

serhiy-storchaka commented Jun 6, 2026

Copy link
Copy Markdown
Member

Yes, a different PR would be better.

All reactions

Sorry, something went wrong.

Uh oh!

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

@serhiy-storchaka serhiy-storchaka closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@vstinner vstinner vstinner left review comments

Uh oh!

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

Assignees

No one assigned

Labels

awaiting review

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.

3 participants

@KowalskiThomas @vstinner @serhiy-storchaka
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.