Skip to content

Make the high fd test really disable garbage collection - #880

Merged
webknjaz merged 1 commit into
cherrypy:mainfrom
rm-you:fix/gc-fixture
Nov 12, 2026
Merged

webknjaz merged 1 commit into
cherrypy:mainfrom
rm-you:fix/gc-fixture

Conversation

@rm-you

@rm-you rm-you commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Note

This is the first PR of the statistics stack: #880 → #858 → #881. The later PRs contain its commit until it merges. The thread pool fixes are a separate stack: #859 → #882.

What kind of change does this PR introduce?

  • 🐞 bug fix
  • 🐣 feature
  • 📋 docs update
  • 📋 tests/coverage improvement
  • 📋 refactoring
  • 💥 other

What do these changes do?

test_high_number_of_file_descriptors needs the server to accept its connection on a file descriptor above the limit, so nothing may free a lower one while it runs. Its _garbage_bin fixture was meant to stop garbage collection, but DefaultGc().nogc() from pypytools only pauses the collections that DefaultGc's own hooks start. Nothing enables those hooks, and CPython has none to install, so the interpreter's collector kept running:

with DefaultGc().nogc() as g:
    g.disable()        # returns at once: the custom GC was never enabled
    gc.isenabled()     # True

The fixture now calls the gc module itself, and turns the collector back on afterwards. Split out of #858 as asked there: #858 makes stopped servers collectable, and a collection during this test then closed the sockets of test clients attached to a server. That failed the test once on CPython 3.14.

Nothing imports pypytools any more, so this PR also drops it from dependencies/direct/py.in and from the pylint hook's dependencies. The lock files still pin it until they are regenerated.

Are there changes in behavior for the user?

No. Tests only.

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

No. The fixture uses the standard library's gc module instead of a third-party context manager.

Related issue number

Needed by #858.

Checklist

Tip

New to open source contributions? Making a lovely PR is a great read.

  • I wrote descriptive pull request text above
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences
  • I think the code is well written
  • Unit tests for the changes exist
  • Integration tests for the changes exist (if applicable)
  • I used the same coding conventions as the rest of the project
  • The new code doesn't generate linter offenses
  • Project documentation (in docs/) and inline docstrings reflect the changes
  • My commits each have a descriptive title and a body explaining the why
    (see good commit messages)
  • I have added a change log entry
    (can be done once the PR number is known; alternatively, you can
    use a related issue number if one exists)
  • I'm planning to squash related commits together before final merge
  • I have read the contribution guide and the
    code of conduct

This change, its tests and this description were written by an AI agent (Anthropic Claude Opus 5.5) on behalf of Adam Harwell (@rm-you). Tested locally with Python 3.11: the complete suite passes at the top of this stack (223 passed, 3 existing expected failures) and with both stacks merged (232 passed), each PR's new tests fail on the commit below it, and all pre-commit hooks pass on the changed files, including mypy-stubtest. Another Claude agent reviewed the changes before they were split into two stacks.

🤖 Generated with Claude Code

@agentscanapp

agentscanapp Bot commented Nov 12, 2026

Copy link
Copy Markdown

Automation signals

Activity patterns show signs of automation.

View full analysis →

Report this account →

Evidence
  • Very high PR volume (daily): 36 PRs within a single 24-hour window
  • High PR volume (weekly): 61 PRs within a single 7-day window
  • 24/7 activity pattern: Active in 23 of 24 hours, with the longest break being only 1.3 hours

Last 5 PRs:

This is an automated analysis by AgentScan

@pyba-chronographer pyba-chronographer Bot added the bot:chronographer:provided A mark meaning that a new change log entry is present within the patch. label Nov 12, 2026
@read-the-docs-community

read-the-docs-community Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cheroot | 🛠️ Build #35840830 | 📁 Comparing 8a119ff against latest (739664c)

  🔍 Preview build  

2 files changed
± history/index.html
± pkg/cheroot.server/index.html

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.99%. Comparing base (739664c) to head (8a119ff).
⚠️ Report is 211 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #880   +/-   ##
=======================================
  Coverage   75.98%   75.99%           
=======================================
  Files          41       41           
  Lines        4931     4932    +1     
  Branches      561      561           
=======================================
+ Hits         3747     3748    +1     
  Misses       1045     1045           
  Partials      139      139           

@rm-you
rm-you marked this pull request as ready for review November 12, 2026 07:26

@webknjaz webknjaz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alright, sounds like I misunderstood how pypytools works the first time I plugged it in. Perhaps it deserves a contrib change note, still?

@rm-you

rm-you commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

I legitimately felt like it might just be broken, at first... but yeah I guess it is just misleading what it does

@webknjaz

Copy link
Copy Markdown
Member

@rm-you yeah, I think it's very likely that I got confused and the shim seemed to have been solving the issue cross-platform at the time. But it's not very well documented.

Could you also include dropping it from the deps lists? (except for the lock files, I'll regenerate them after the merge)

@webknjaz

Copy link
Copy Markdown
Member

Feel free to use separate atomic commits on the topic branch — I almost always use true merge in this repo.

test_high_number_of_file_descriptors needs the server to accept its
connection on a file descriptor above the limit, so nothing may free a
lower one while it runs. Its _garbage_bin fixture was meant to stop
garbage collection, but pypytools' DefaultGc.nogc() only pauses the
collections that DefaultGc's own hooks start. Nothing enables those
hooks, and CPython has none to install, so the interpreter's collector
kept running.

This matters once stopped servers can be collected (cherrypy#858): a
collection then closes the open sockets of test clients that fixtures
attached to a server, and the server can take one of the freed low
file descriptors. That failed the test once on CPython 3.14 in CI.

The fixture now disables the collector through the gc module, which
CPython and PyPy both support, and turns it back on afterwards. A
fixture's code after its yield runs even when the test fails, so it
needs no try/finally.

Nothing else uses pypytools, so drop it from the test dependencies
and from the pylint hook's environment. The lock files still pin it
until they are regenerated.

Assisted-By: Anthropic Claude Opus 5.5
Signed-off-by: Adam Harwell <flux.adam@gmail.com>
@rm-you

rm-you commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Sure, will drop those

@webknjaz
webknjaz merged commit e5db8e5 into cherrypy:main Nov 12, 2026
155 of 159 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentscan:automation-signals bot:chronographer:provided A mark meaning that a new change log entry is present within the patch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants