Skip to content

Drop dead retry loop in md_clone_from_ht and fix suspend comments - #1486

Merged
asvetlov merged 2 commits into
aio-libs:masterfrom
asvetlov:fix-suspend-comment-and-dead-clone-retry
Sep 20, 2026
Merged

asvetlov merged 2 commits into
aio-libs:masterfrom
asvetlov:fix-suspend-comment-and-dead-clone-retry

Conversation

@asvetlov

Copy link
Copy Markdown
Member

What do these changes do?

An automated review of #1484 flagged md_readonly_find_next()'s allocation
as a potential use-after-free, reasoning that a blocking PyMem_Malloc()
call could transiently suspend the held critical section. That mechanism
does not exist: per #1469, PyMem_Malloc() never suspends an acquired
critical section on the free-threaded build, so the finding was a false
positive there.

Chasing the same claim through the rest of hashtable.h turned up two
real issues. md_clone_from_ht() still carried the exact
retry-on-staleness loop #1469 already proved dead in _md_resize(), just
never cleaned up here; this drops it the same way. _md_del_at(),
_md_del_at_for_upd() and _md_replace() have a real suspension risk
(a decref of the old key/value can run a finalizer or weakref callback),
but their comments wrongly attributed it to "the same allocator lock as
PyMem_Malloc()", pointing at a comment that no longer exists anywhere in
the file after #1469; reworded those to name the actual mechanism.

Are there changes in behavior for the user?

No.

Is it a substantial burden for the maintainers to support this?

No; this only touches internal comments and removes unreachable code in
one free-threaded-only helper.

Related issue number

Related to #1484 and #1469, not closing either.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist -- N/A, no behavior change; the
    touched paths are already exercised by the existing suite on both
    backends
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt -- N/A, no such file in this repo
  • Add a new news fragment into the CHANGES/ folder
  • make doc-spelling passes and any new technical words are added to docs/spelling_wordlist.txt

Drafted with Claude Code (Claude Sonnet 5); reviewed by :user:asvetlov.

Agent run details (optional, for reviewers)

Tests (isolated venvs, this branch rebased onto current upstream master):

  • C extension, default build: pytest tests -q -- 2059 passed
  • Free-threaded debug build (MULTIDICT_DEBUG_BUILD=1): pytest tests -q -k "not test_leak" --no-cov -- 2049 passed
  • Free-threaded debug build under ASan+UBSan (MULTIDICT_ASAN_BUILD=1): same command under LD_PRELOAD=libasan.so ASAN_OPTIONS=detect_leaks=0 -- 2049 passed, no sanitizer reports
  • Pure Python (MULTIDICT_NO_EXTENSIONS=1, pytest --no-c-extensions --no-cov): 1037 passed

Lint: make doc-spelling passes; pre-commit hooks (clang-format, changelog filename/role checks) passed on commit.

An automated review of aio-libs#1484 flagged md_readonly_find_next()'s
allocation as a potential use-after-free, reasoning that a blocking
PyMem_Malloc() could transiently suspend the critical section. That
claim does not hold: per aio-libs#1469, PyMem_Malloc() never suspends an
acquired critical section, so the finding was a false positive.

The same false premise was still present elsewhere in hashtable.h.
md_clone_from_ht() carried the exact retry-on-staleness pattern aio-libs#1469
already proved dead in _md_resize(), just never cleaned up there;
drop it the same way. _md_del_at(), _md_del_at_for_upd() and
_md_replace() attributed their (real) suspension risk to "the same
allocator lock as PyMem_Malloc()", a comment that no longer exists
anywhere in the file; reworded those comments to name the actual
mechanism, a decref running a finalizer or weakref callback.

No behavior change; verified against the C extension (default and
free-threaded debug + ASan/UBSan builds) and the pure-Python backend.
@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Sep 20, 2026
@asvetlov
asvetlov marked this pull request as ready for review September 20, 2026 13:31
@asvetlov
asvetlov requested a review from webknjaz as a code owner September 20, 2026 13:31
@greptile-apps

greptile-apps Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

Safe to merge.

Reviews (2) · Last reviewed commit: "Update CHANGES/1486.misc.rst"

Comment thread CHANGES/1486.misc.rst Resolved
@codspeed

codspeed Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 266 untouched benchmarks


Comparing asvetlov:fix-suspend-comment-and-dead-clone-retry (a41275b) with master (b8fc573)

Open in CodSpeed

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@asvetlov
asvetlov merged commit 50a6188 into aio-libs:master Sep 20, 2026
61 checks passed
@asvetlov
asvetlov deleted the fix-suspend-comment-and-dead-clone-retry branch September 20, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided There is a change note present in this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant