Skip to content

fix(cuda.core): pick one owner when IPC pool registrations of one UUID race - #3524

Merged
juenglin merged 10 commits into
NVIDIA:mainfrom
juenglin:fix-ipc-registry-reentry-and-gpu-check
Nov 24, 2026
Merged

juenglin merged 10 commits into
NVIDIA:mainfrom
juenglin:fix-ipc-registry-reentry-and-gpu-check

Conversation

@juenglin

@juenglin juenglin commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow-up to #3511, which deferred two review items so it could merge while #3516 waited on it.

Pick one owner when registrations of one UUID race in MP_register. The registry lookup and insertion both run Python code (WeakValueDictionary methods, uuid.UUID.__hash__), where a garbage collection can start and a callback can register the same UUID on the same thread (the lock is reentrant). The re-entrant call inserted its resource, then the outer call overwrote it, leaving two owners of one driver pool with the registry holding only one. The overwrite predates #3511.

The registry is now a plain dict keyed by uuid.UUID.bytes, mapping to a weakref.KeyedRef of the resource. MP_register does everything that can run Python before taking _registry_lock; under the lock it looks the key up, inserts the reference and sets the handle's UUID without running any Python code. Nothing can re-enter between the lookup and the insertion, so there is no half-registered state, no rollback and no test hook in production code. If a handle shared by two imports gets its UUID between validation and the lock, the call validates again. This replaces this PR's earlier "registration in progress" mark, which needed several rounds of review fixes.

register() and from_registry() now raise TypeError for a key that is not a uuid.UUID, as their annotations already say.

Check every supported GPU after the re-import race. test_reimport_racing_the_last_release_keeps_access only checked access on the default GPU, but the final release of a pinned pool revokes access one GPU at a time. It now checks every GPU the pool grants access to.

Tests

  • A uuid.UUID subclass runs a nested registration, a nested registration plus close, or a failure at each Python-visible use of the key (__hash__, __eq__, bytes), with separate and with shared handles.
  • The garbage-collection test also registers the UUID in progress from a collection callback.
  • New tests cover dead-entry removal and the TypeError for non-UUID keys.

With main's MP_register, the key sweep fails for every nested-registration case. The retry for a shared handle can occur only on a free-threaded build and has no deterministic test. The _set_ipc_pool_release_delay_for_testing hook from #3511 is untouched and remains a separate follow-up.

Scope

cuda.core only: no counterpart in cuda_bindings_12/ or cuda_bindings_13/, and no BEGIN SYNCED groups in the touched files. No release note: the fix hardens an essentially unobservable condition, and the other change is test-only.

Checklist

  • I have read the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@juenglin juenglin added this to the cuda.core 1.4.0 milestone Nov 21, 2026
@juenglin juenglin added bug Something isn't working cuda.core Everything related to the cuda.core module labels Nov 21, 2026
@juenglin juenglin self-assigned this Nov 21, 2026
@copy-pr-bot

copy-pr-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Shared memory pool imports now resolve to a single registered pool when registrations overlap, including nested registrations and cases where the pool is closed during registration.
    • Memory-pool access checks now cover all devices supported by a pool, rather than only the default device, including during the last-release race scenario.
    • Registry lookups and registrations now reject non-UUID keys with a TypeError.
    • Entries for dropped resources are removed, allowing later registrations to proceed cleanly.

The IPC registry now uses UUID-byte keys and keyed weak references. Registration synchronizes lookup and insertion, and registry operations validate UUID keys. Tests cover re-entrant and interrupted registration, dead-entry removal, equal UUID objects, and pool access across supported devices.

Changes: IPC registry registration

Layer / File(s) Summary
Registry lookup and registration
cuda_core/cuda/core/_memory/_ipc.pyx, cuda_core/cuda/core/_memory/_ipc.pxd, cuda_core/cuda/core/_memory/_ipc.pyi
The registry uses UUID-byte keys and keyed weak references. Lookup validates UUID keys. MP_register prepares the reference before locking, then synchronizes lookup and insertion.
Registration and cleanup verification
cuda_core/tests/helpers/memory.py, cuda_core/tests/memory_ipc/*
Tests cover invalid keys, equal UUID objects, re-entrant registration during garbage collection, interruptions during registration, and removal of dead entries. Pool-access checks cover all supported devices.

Possibly related PRs

  • NVIDIA/cuda-python#3511: Adds shared ownership for repeat IPC pool imports and the duplicate-import tests extended here.
  • NVIDIA/cuda-python#3509: Changes the IPC import sequence for pinned pools, which interacts with the registration sequence changed here.

Suggested reviewers: mdboom

Change: Bug fix

Merge Risk: Minimal · previous review 1aeab

This change makes concurrent or re-entrant IPC pool registration of the same UUID settle on one owner that is immediately usable. Tests cover the main re-entry and cleanup paths. No outstanding merge-blocking risk remains.

Security architecture risk: Low · up to 1aeab

The change prevents competing registrations from overwriting a live owner for an ordinary UUID. A caller-supplied UUID subclass can still make lookup select the wrong local pool or miss a live owner. No new remote entrypoint or expansion of driver privileges was identified.

Retained concerns

  • Low · reliability · inferred: The new registry key is taken from an overridable UUID property, while registration still checks a handle's UUID using object equality. An accepted subclass can therefore make distinct UUIDs address the same entry, or make a later lookup miss a live owner. The former can return a different open pool; the latter can send an import down the new-pool path instead of reusing its registered owner. This is a new way for identity to diverge, although the previous implementation also trusted subclass hashing and equality.
Security review details

Security Blast Radius

  • inferred — The evidenced exposure is selection or reuse of a pool in the receiving process's registry. The changed path requires a caller or reconstructed handle to supply the noncanonical UUID object; no new untrusted byte-only ingress is shown.

Trust Boundaries and Controls

  • observed — Allocation-handle import still rejects a closed IPC handle before consulting the registry and checks a matched resource's type and open state before returning it.

Resilience and Maintainability Implications

  • observed — Cleanup removes an entry only if it still contains the weak reference being finalized, so delayed cleanup cannot erase a replacement owner. The documented insertion-error path can build a traceback under the lock, but it does not reach the subsequent handle UUID assignment.

Hardening Proposals

  • proposed — Use one stable UUID representation for both registry keys and handle conflict checks. Define how subclasses are handled so an override cannot change pool identity independently of the UUID value.
Finishing Touches

Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 76678b3 and 1aeab59.

Files selected for processing: 3

  • cuda_core/cuda/core/_memory/_ipc.pyx
  • cuda_core/tests/memory_ipc/test_errors.py
  • cuda_core/tests/memory_ipc/test_ipc_pool_duplicate_import.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.

@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test e04e278

@juenglin
juenglin enabled auto-merge (squash) November 21, 2026 04:08
@juenglin
juenglin requested review from Andy-Jost and rwgk November 21, 2026 04:08

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3275ccf and e04e278.

Files selected for processing: 3

  • cuda_core/cuda/core/_memory/_ipc.pyi
  • cuda_core/cuda/core/_memory/_ipc.pyx
  • cuda_core/tests/memory_ipc/test_ipc_pool_duplicate_import.py
Files with no reviewable changes: 1

  • cuda_core/cuda/core/_memory/_ipc.pyi
Files skipped from review as they are similar to previous changes: 1

  • cuda_core/tests/memory_ipc/test_ipc_pool_duplicate_import.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.

Comment thread cuda_core/cuda/core/_memory/_ipc.pyx Resolved
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor
Doc Preview CI
Preview removed because the pull request was closed or merged.

@rwgk

rwgk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

codex GPT-6.2-Sol ultra:

Findings

  • [P1] Reentrant register() can return an unusable resource and lead to a crash. I confirmed the open CodeRabbit finding. The nested call returns the outer resource before its UUID is set or from_registry() can find it. The new test checks only after the outer call completes, so it misses both failures. In a minimal Cython reproducer using the PR’s registration logic, closing the resource returned to the callback caused the outer call to segfault when it resumed and accessed the cleared IPC data. Finish publication before either call can return the winner, and check the UUID and registry lookup inside the callback. Source · Open thread
  • [P3] Keep the reentry hook in the test harness. The PR adds a callable production hook that runs Python code under the registry lock. Rob raised the same concern about the IPC release-delay hook on fix(cuda.core): share ownership of repeat imports of an IPC memory pool #3511. A test-owned callback can exercise the reentry path. New hook · Related feedback

PR status

@juenglin
juenglin force-pushed the fix-ipc-registry-reentry-and-gpu-check branch from e04e278 to ebf78c6 Compare November 24, 2026 03:53
@juenglin

Copy link
Copy Markdown
Contributor Author

Thanks, all three points hold, and I reproduced the P1 crash.

  • [P1] Reentrant register() returns an unusable resource. Fixed in ebf78c6. The outer call now sets the resource's UUID before marking it as being inserted. A re-entrant call that finds the mark inserts that resource into the registry before returning it. The outer call no longer touches the resource's IPC data after marking it, and it restores the previous UUID unless the registry ends up holding the resource. The test now checks uuid and from_registry() inside the callback and has a variant that closes the resource there. Against the previous head, all four variants fail with "was not found", and the close variants crash with exit code -11 once only the registration part of the fix is restored.
  • Merge conflict. The branch is rebased onto main. The every-GPU assertion is now in test(cuda.core): cover re-importing a pinned pool after a release with a pending free #3531's ExitStack version of the race test.
  • [P3] Keep the reentry hook out of production code. We will address this, together with Rob's comment on #3511 about _set_ipc_pool_release_delay_for_testing, in a follow-on PR rather than add another CI round here. Both hooks need different treatment, so they are best handled together: a test-owned uuid.UUID subclass can drive the reentry test without any production hook, but the release delay runs in the C++ deleter with the GIL released and needs a different approach.

@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test ebf78c6

@rwgk

rwgk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Re-reviewed with codex at ebf78c6:

Ralf J fixed the original callback crash and resolved the merge conflict. I found two issues in the new UUID rollback.

  • [P2] Rollback can clear the winning resource’s UUID. Two imports can share the same UUID-less IPCAllocationHandle. If the second import wins during reentry at marker insertion, the outer call restores None on the shared handle. from_registry(key) still finds the winner, but winner.uuid is None. Source
  • [P3] A failed marker insertion leaves the UUID assigned. The UUID write happens before the dictionary insertion, and rollback starts afterward. If insertion raises MemoryError, registration fails but the resource keeps the UUID. A retry with a different UUID then raises ValueError. Source

I reproduced both in a Cython harness. Keeping the handle reference, then inserting the marker before reading and assigning the UUID, fixed both cases in the harness.

@juenglin
juenglin marked this pull request as draft November 24, 2026 15:28
auto-merge was automatically disabled November 24, 2026 15:28

Pull request was converted to draft

The release of an imported pool revokes device access one GPU at a time, so
the test that re-imports a pool while the last owner is released must check
that access survives on every GPU the pool grants it to, not only the
current one. Add pool_supported_devices to name those GPUs.
…n code

MP_register looked a UUID up in a WeakValueDictionary and then inserted into
it. Both are Python code, as is hashing a uuid.UUID, so a garbage-collection
callback or finalizer can run between the lookup and the insertion and
register the same UUID on the same thread. The registry lock is reentrant, so
that call proceeds, inserts its resource and returns it, and the outer call
then overwrites the entry: two resources own one driver pool and the registry
holds only one of them.

Key the registry by uuid.UUID.bytes, which a dict hashes and compares in C,
and store a weakref.KeyedRef of the resource. MP_register does everything that
can run Python code before it takes the lock. Under the lock it looks the key
up, inserts the reference and sets the handle's UUID without running any
Python code, so nothing can re-enter between the lookup and the insertion and
there is no intermediate state or rollback. The removal callback takes the
lock as well, which is safe because the lock is a leaf. Imports can share one
IPCAllocationHandle; if another registration gave it its UUID between
validation and the lock, the call validates again.

register() and from_registry() now raise TypeError for a key that is not a
uuid.UUID.

Test the registration by interrupting it at every use of its key: a UUID
subclass runs a nested registration, a nested registration followed by a
close, or a failure at the k-th hash, comparison or bytes read, for k until
the registration no longer reads the key, with separate and with shared
handles. That needs no hook in the implementation. Also register one UUID from
a garbage-collection callback while another import registers it, and check
that the entry of a dropped resource is removed and its UUID can be reused.
@juenglin
juenglin force-pushed the fix-ipc-registry-reentry-and-gpu-check branch from dae4418 to a9637c9 Compare November 24, 2026 17:13
@juenglin

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews. Both of your last two rounds came from the same cause: the "registration in progress" mark made a half-registered resource visible to other code, so every fix on top of it opened another interleaving to analyze. I have replaced that approach instead of patching it again, and force-pushed a rebased branch (a9637c9) with two commits.

  • Registration fix. registry is now a plain dict keyed by uuid.UUID.bytes (hashed and compared in C) holding a weakref.KeyedRef. MP_register does everything that can run Python code before it takes _registry_lock. Under the lock it looks the key up, inserts the reference and sets the handle's UUID without running any Python code, so a nested registration cannot run between the lookup and the insertion. There is no mark, no rollback and no intermediate state, so the P1, P2 and P3 cases from your reviews cannot occur. A shared handle that gets its UUID between validation and the lock is validated again.
  • Test hook removed. _set_register_reentry_hook_for_testing is gone, which addresses the production-hook point in the earlier P3. Reentry is driven by a test-owned uuid.UUID subclass that fires an action at the k-th use of the key (__hash__, __eq__, bytes), for a nested registration, a nested registration plus close, and a failure, each with separate and with shared handles. The garbage-collection test now also registers the UUID in progress from a collection callback, and there are tests for dead-entry removal and for a non-UUID key.
  • Behavior change. register() and from_registry() raise TypeError for a key that is not a uuid.UUID.
  • Verification. With main's MP_register swapped in, the key sweep fails for every nested-registration case. On this branch tests/memory_ipc, tests/test_memory.py and tests/test_object_protocols.py pass on 595.99.02. The shared-handle retry needs a free-threaded build and has no deterministic test.

The _set_ipc_pool_release_delay_for_testing hook from #3511 (Rob's comment) is still a separate follow-up. The PR description has the details.

@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test a9637c9

…C registry lock

If inserting into the registry fails, building the traceback allocates objects while _registry_lock is held, and on Python 3.11 that can start a garbage collection. Record the exception next to the rule that no Python code runs under the lock.
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 76678b3

@juenglin
juenglin marked this pull request as ready for review November 24, 2026 17:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ebf78c6 and 76678b3.

Files selected for processing: 5

  • cuda_core/cuda/core/_memory/_ipc.pxd
  • cuda_core/cuda/core/_memory/_ipc.pyi
  • cuda_core/cuda/core/_memory/_ipc.pyx
  • cuda_core/tests/memory_ipc/test_errors.py
  • cuda_core/tests/memory_ipc/test_ipc_pool_duplicate_import.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.

Comment thread cuda_core/cuda/core/_memory/_ipc.pyx Resolved
MP_register assigned the handle's UUID on every successful registration.
When the handle already held an equal but distinct uuid.UUID object, the
assignment released the old object under the registry lock. The handle's
UUID is read without that lock, by MP_register before it takes the lock and
by IPCAllocationHandle.uuid, so on a free-threaded build a reader could load
the old object, lose it to the release, and take a reference to freed
memory. Releasing it under the lock could also run the __del__ of a
uuid.UUID subclass there, where no Python code may run.

Both cases are reachable through register(): an exported resource has a
UUID from creation and can be registered under an equal one, and a handle
shared by two imports keeps its UUID after the import that registered it is
dropped.

Assign the UUID only when the handle has none. The field then changes once,
from None to an object that lives as long as the handle, so an unlocked
read cannot see a released object.

Test both routes by registering under an equal but distinct UUID and
checking that the resource still returns the original object.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 1aeab59

@rwgk

rwgk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I'm copy-pasting two codex responses:

Standard re-review request

I re-reviewed the latest GitHub head. The rewrite addresses both earlier UUID rollback findings and removes the production reentry hook. The latest commit also preserves the existing UUID object when an equal UUID is registered. Three issues remain. Author’s response · UUID follow-up

  • [P1] A free-threaded lookup can use a freed weak reference. Cython compiles the typed dict.get() into a borrowed lookup followed by a separate reference-count increment. Concurrent cleanup can free the KeyedRef between those operations. A minimal Cython harness segfaulted on CPython 3.14t. Calling ordinary dict.get() through an object-typed receiver passed the same stress test. Lookup and cleanup
  • [P2] A registry hit can expose a pool before its first UUID is assigned. The writer inserts the entry before setting the UUID, and lookup skips the writer’s lock. A free-threaded Cython harness using the latest registration code observed a live registry hit with uuid is None. Taking _registry_lock for lookup and UUID snapshots would address both concurrency findings. Publication code
  • [P3] Insertion failure can bring back the lock inversion on Python 3.11. An injected MemoryError triggered a GC callback while the registry lock was held. A finalizer waiting for an application lock can deadlock with a thread that holds that lock and is waiting to remove a weak registry entry. Keep traceback construction outside the registry lock. Lock and cleanup

Analysis of the findings-fixes-re-review cycles

The first two review rounds found bugs introduced by the proposed fixes. The latest round found a new crash path, a lock-order problem that came back in a narrower form, and a publication race that was already on main.

The original bug was a same-thread reentry problem. Registration could find the UUID absent, then trigger a Python garbage-collection callback before inserting it. The callback could register the same UUID successfully, and the outer call would overwrite its entry. #3511 added a reentrant lock, which serialized writers on different threads while still allowing that callback to enter on the same thread. Code before #3511 · Code after #3511

Review finding Where it came from
The nested caller got an unfinished resource and could crash the outer call by closing it. New in the first reviewed fix. The in-progress marker let the nested call return the outer candidate before its registration was complete. Marker implementation
Rollback could erase the winner’s UUID or leave a UUID on a failed registration. New in the next fix. Assigning the UUID early solved the unfinished return and created two rollback cases. The rewrite removed the marker and both cases. Rollback implementation
A free-threaded lookup could use a freed weak reference. Introduced by the PR’s typed-dict design. That design appeared in the first discarded attempt, disappeared from the marker revisions we reviewed, and came back in the rewrite. First attempt · Rewrite
Another thread could find a registered pool whose UUID was still None. Already on main. The old code published the registry entry before assigning the UUID. The rewrite put both writes under one lock, but readers still skip it. I missed this separate cross-thread path in the earlier rounds. Replacing an equal UUID object was also an older hazard, and the write-once follow-up addresses that particular lifetime problem. Base code · Write-once follow-up
Weakref cleanup could deadlock on Python 3.11 after an insertion failure. Reintroduced in a narrower form. The first dict attempt took the registry lock during cleanup while ordinary registration could trigger GC under that lock. The rewrite moves that work outside the lock on the normal path. Building a traceback after a failed insertion can still trigger GC while the lock is held. Rewrite’s locking code

The early reviews followed the original same-thread callback scenario. The registry rewrite also changed how free-threaded readers acquire references and when they can see a new entry. Reviewing those reader paths alongside the writer would have surfaced the older publication gap sooner.

juenglin and others added 3 commits November 24, 2026 11:08
Without the GIL, a registry lookup outside _registry_lock had two
problems:

- Cython compiles get() on a typed dict into a borrowed lookup followed
  by a separate reference-count increment. A concurrent removal of a
  dead entry could free the weak reference in between.
- A registration inserts the entry and then sets the handle's UUID. A
  lookup between the two returned a registered resource whose UUID was
  None.

_registry_lookup now takes the lock, so every access to the registry is
under it. The lock is reentrant; MP_register already calls the lookup
while holding it.

The new test registers and drops resources under one UUID on one thread
while other threads look the UUID up. On a free-threaded CPython 3.14
build without the fix it failed in every run, with segfaults and with
hits whose UUID was None. With the fix it passed in 20 runs. With the
GIL it only checks that the lookups succeed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Adopt the test helpers from NVIDIA#3544 in the tests this branch adds: import
pools with enter_imported_pool, which replaces _enter_import, and run the
lookup race test's threads with run_in_threads, which replaces
_run_threads and the hand-written error collection.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…its own

Free-threaded CI runs tests with pytest-run-parallel, whose threads share
fixtures. With a shared ipc_memory_resource, one thread registered the
resource before another checked that it was not registered yet, so the
test failed under --parallel-threads. Each thread now creates its own
resource with ipc_memory_resource_factory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juenglin

juenglin commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the re-review. P1 and P2 are confirmed and fixed. P3 stays as documented at _registry_lock.

P1 and P2 (fixed in 50d49d1): _registry_lookup now takes _registry_lock itself, so every access to the registry is under the lock. This covers both lookups: MP_from_registry and MP_from_allocation_handle. The lock is reentrant, and MP_register already called the lookup while holding it. Both findings had one cause: the rewrite put writers under the lock and left readers outside it.

I reproduced both on CPython 3.14t against cuda.core itself, not only a model:

  • Cython 3.2.9 compiles the typed dict.get() into PyDict_GetItemWithError followed by a separate Py_INCREF. Cython 3.3.1 generates the same code, so upgrading Cython would not fix P1.
  • The new test test_lookups_racing_registrations_find_registered_resources registers and drops resources under one UUID on one thread while four threads look it up. Without the fix it failed in every run, with segfaults (P1) and with assert mr.uuid is key failures (P2). With the fix it passed in 20 of 20 runs. With the GIL it only checks that the lookups succeed.

Also in this push:

  • Merged main. The tests this PR adds now use enter_imported_pool and run_in_threads from test(cuda.core): drain imported pool frees in IPC tests and share a thread runner #3544.
  • 30b2371: test_register_keeps_the_uuid_object_the_resource_already_has failed under --parallel-threads, because pytest-run-parallel shares fixtures between threads. It now creates a resource of its own.
  • All of tests/memory_ipc passes on 3.14t with --parallel-threads=4, as free-threaded CI runs it: 205 passed, 63 skipped.

@juenglin

Copy link
Copy Markdown
Contributor Author

/ok to test 30b2371

@rwgk

rwgk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

codex GPT-6.2-Sol ultra:

[P2] The new lookup lock can deadlock during a successful registration on CPython 3.11. MP_register holds _registry_lock when it calls _registry_lookup, which enters the same lock again. Cython allocates bound methods for that inner with, and the allocation can trigger garbage collection while the outer lock is held. A GC callback can then wait for an application lock held by a thread whose weakref cleanup is waiting for _registry_lock. I reproduced the two-thread deadlock in a Cython harness. The same harness completed when registration called a helper that looked up the entry under the lock it already held. Standalone lookups should still acquire the lock. Lookup · Registration

The update fixes both free-threaded registry-read findings from the last review. Ralf J reproduced both on the built extension, and the regression test passed 20 of 20 runs with the fix. The new deadlock occurs without an insertion failure, so it falls outside the documented risk Ralf J accepted in Slack. Author’s verification · Slack context

rwgk added 3 commits November 24, 2026 12:29
Use the lock-held lookup helper during registration. Entering a second lock scope can allocate bound context manager methods and start a collection on Python 3.11 while the registry lock is held. A finalizer can then deadlock with weakref cleanup.

Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
On CPython 3.11, wait for another thread to look up a registered pool when garbage collection starts during registration. A nested registry lock can start GC while the lock is held and block that lookup.

Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
Signed-off-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
@rwgk

rwgk commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

/ok to test 0e3e363

@juenglin
juenglin enabled auto-merge (squash) November 24, 2026 22:24

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM based on codex reviews, and discussions on DM.

@juenglin
juenglin merged commit 7623950 into NVIDIA:main Nov 24, 2026
224 of 226 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 25, 2026
Removed preview folders for the following PRs:
- PR #3499
- PR #3524
- PR #3543
- PR #3544
- PR #3546
- PR #3551
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cuda.core Everything related to the cuda.core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants