test(core): run the fd-leak check on success, not only after a failure - #2583
Open
LeSingh1 wants to merge 1 commit into
Open
test(core): run the fd-leak check on success, not only after a failure#2583LeSingh1 wants to merge 1 commit into
LeSingh1 wants to merge 1 commit into
Conversation
`CheckFDLeaks.__exit__` compares the descriptor count under an inverted guard:
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
gc.collect()
final_fds = self.process.num_fds()
assert final_fds == self.initial_fds
return False
`exc_type is not None` means "the with-body raised". So the comparison runs
only when the test has already failed for some other reason, and never on the
normal path -- which is the only path its two users take.
Both of them delegate their entire assertion power to this class:
def test_alloc_handle(ipc_memory_resource):
mr = ipc_memory_resource
with CheckFDLeaks():
[mr.allocation_handle for _ in range(10)]
`test_alloc_handle` and the 12 parametrizations of `test_pass_object`
(4 object kinds x 3 launchers, covering the success, launch-failure and
reduce-failure paths) contain no assertion of their own, so all 13 currently
pass unconditionally. An fd leak in `allocation_handle`, in Buffer / mr /
ipc_descriptor pickling, or on either failure path produces no failure --
`self.initial_fds` is recorded in `__enter__` and then discarded.
On the branch it did run, the assert was also harmful: raising from `__exit__`
replaces the exception the test was really reporting, so a genuine error would
surface as a bare fd-count mismatch.
Guard on `exc_type is None` and add the counts to the assertion message.
Note for reviewers: this makes a check live that has never executed. If it now
fails, that is the leak it was written to catch, not a defect in this change.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
CheckFDLeaks.__exit__compares the descriptor count under an inverted guard (test_leaks.py:128-133):exc_type is not Nonemeans "thewithbody raised". So the comparison runs only when the test has already failed for some other reason, and never on the normal path — which is the only path its two users take.Both of them delegate their entire assertion power to this class:
test_alloc_handleand the 12 parametrizations oftest_pass_object(4 object kinds × 3 launchers, covering the success, launch-failure and reduce-failure paths) contain no assertion of their own. All 13 therefore pass unconditionally today:self.initial_fdsis recorded in__enter__and then discarded. A descriptor leak inallocation_handle, inBuffer/mr/ipc_descriptorpickling, or on either failure path produces no failure.On the one branch where it did run, the assert was also actively harmful: raising from
__exit__replaces the exception the test was really reporting, so a genuine error surfaces as a bare fd-count mismatch.Fix
Guard on
exc_type is None, and put the counts in the assertion message so a failure names the leak size instead of justassert 41 == 38.Note for reviewers: this makes a check live that has never executed. If it now fails, that is the leak it was written to catch, not a defect in this change. I have no GPU here and cannot tell you either way — see below.
What I ran
Environment: macOS, no CUDA driver and no CUDA toolkit. These tests additionally require Linux (
USING_FDS = platform.system() == "Linux"),psutil, and a working IPC memory resource, so they are triple-unrunnable here.cuda_core/tests/memory_ipc/test_leaks.py.python -m py_compile,ruff check,ruff format --checkon the changed file — clean, no new findings against amainbaseline.CheckFDLeakshas exactly two users,test_alloc_handle(:31) andtest_pass_object(:102), and neither has any other assertion;prime()in__enter__exists to warm up the allocations so the baseline is stable, which only makes sense for a check that runs on success.