Skip to content

Conversation

esafak
Copy link
Contributor

@esafak esafak commented Aug 4, 2025

Fixes #2935

  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

* Enhance the file limit test to accommodate different exception types. A RedHat user reported a RuntimeError in pypa#2935
* The test now catches `SystemExit` or `RuntimeError` which can be raised by the CLI.

Fixes pypa#2935

Signed-off-by: Emre Şafak <[email protected]>
Copy link
Contributor

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

I'm holding this until upstream confirms why we're getting RuntimeError and not SystemExit.

@frenzymadness
Copy link
Contributor

I've tried this patch with an update from RuntimeError to OSError but I'm getting:

            # Typically SystemExit, but RuntimeError was observed in RedHat
            expected_exception = typing.Union[SystemExit, OSError]
>           with pytest.raises(expected_exception) as too_many_open_files_exc:
E           TypeError: 'typing.Union' object is not iterable

@esafak
Copy link
Contributor Author

esafak commented Aug 5, 2025

I've tried this patch with an update from RuntimeError to OSError but I'm getting:

            # Typically SystemExit, but RuntimeError was observed in RedHat
            expected_exception = typing.Union[SystemExit, OSError]
>           with pytest.raises(expected_exception) as too_many_open_files_exc:
E           TypeError: 'typing.Union' object is not iterable

no worries, I'll use a tuple. Let's worry about the exception types. I was able to trigger a RuntimeError in MacOS by commenting out

    # if soft_limit > 1024:
    #     pytest.skip("soft limit for open files is too high to reliably trigger the error")

esafak and others added 7 commits August 5, 2025 08:54
We don't need to skip if the soft limit is high; we're going to reduce it anyway.

Signed-off-by: Emre Şafak <[email protected]>
Signed-off-by: Emre Şafak <[email protected]>
* Add exception handling for `resource.setrlimit` to skip tests on implementations that don't support it (e.g., PyPy, GraalPy).
* Adjust the number of opened file descriptors to account for JIT
  implementations which may consume more initially.
* Add specific checks for `OSError` with `errno.EMFILE` and the "Too many open files" message for JIT environments.

Signed-off-by: Emre Şafak <[email protected]>
* Add checks for `IS_GRAALPY` and `IS_PYPY` to conditionally adjust file descriptor limits.
* Refactor the test to use `pytest.raises` for more robust assertion of `OSError` during file descriptor exhaustion.
* Ensure that the `EMFILE` error code and specific error message are checked for JIT environments.

Signed-off-by: Emre Şafak <[email protected]>
Otherwise we'll have to repeat the logic since the error does not happen outside of JIT.

Signed-off-by: Emre Şafak <[email protected]>
@gaborbernat gaborbernat merged commit fa67f8d into pypa:main Aug 7, 2025
42 checks passed
@esafak esafak deleted the fix/2935-too-many-open-files branch August 7, 2025 15:49
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.

[self-tests] new test_too_many_open_files fails
4 participants