Skip to content

Release fds and the multicast handle on Buffer construction error paths - #33

Open
yurekami wants to merge 1 commit into
MoonshotAI:masterfrom
yurekami:fix-buffer-ctor-leaks
Open

Release fds and the multicast handle on Buffer construction error paths#33
yurekami wants to merge 1 commit into
MoonshotAI:masterfrom
yurekami:fix-buffer-ctor-leaks

Conversation

@yurekami

Copy link
Copy Markdown

Fixes #17.

Guards the acquire-without-finally windows reported there, on all four sites, using only bindings the file already imports:

  • _exchange_ipc_fds: if the recv loop raises (timeout, or the explicit no-fd RuntimeError), fds already duplicated into this process by SCM_RIGHTS are now closed before the exception propagates. sock.close() in the existing finally never covered them; they are plain ints with no Python owner.
  • _map_nvl_dist_tensor: os.close(local_fd) moved into a finally around the exchange, so the exported fd cannot leak when the exchange raises.
  • _create_nvl_multicast_view: the window between nvl_multicast_create and a completed import is now wrapped; on error the root closes its exported fd (finally) and releases the multicast handle via the existing nvl_release_mem_handle binding (a multicast object handle is a CUmemGenericAllocationHandle, so cuMemRelease applies). Success-path behavior and timing are unchanged.
  • create_nvl_single_owner_tensor: same finally treatment for the owner's exported fd.

A leaked exported fd also pins the underlying cuMemCreate allocation (release only completes when all shareable references are gone), so on the production path this held the hidden_buf chunk, not just an fd table entry — details in #17.

Verification: behavior verified by reading against master @ 2bd860b plus py_compile; I don't have a multi-GPU NVLink box available, so the error paths were not executed here. Happy to adjust if you'd rather scope the multicast guard differently.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Two resource leaks on Buffer construction error paths (multicast handle, IPC fds)

1 participant