Skip to content

BUG Fix Callback's _worker_connections cache leak (#34734) - #34743

Closed
Iitian001 wants to merge 1 commit into
scikit-learn:mainfrom
Iitian001:fix-callback-fd-leak
Closed

Iitian001 wants to merge 1 commit into
scikit-learn:mainfrom
Iitian001:fix-callback-fd-leak

Conversation

@Iitian001

Copy link
Copy Markdown

Resolves #34734 by replacing the standard dict with an LRU cache (maxsize=16). When a connection is evicted from the cache, it is closed explicitly to free the file descriptor and prevent EOFError under heavy workload with persistent workers.

@github-actions

Copy link
Copy Markdown

Thank you for your interest in contributing to scikit-learn.

The linked issue is still under discussion, and the maintainers have not yet reached consensus on how it should be resolved. Before opening a pull request, please review the "Issues tagged 'Needs Triage'" section of the Contributing Guide:
https://scikit-learn.org/stable/developers/contributing.html#issues-tagged-needs-triage

For now, we are closing this pull request.

  • If you believe your proposed change addresses the linked issue, please explain your proposal in that issue, and allow time for discussion with the maintainers so that consensus can be reached before implementation begins.

  • If you believe this is a mistake, please leave a comment on the linked issue as well.

@github-actions github-actions Bot closed this Aug 13, 2026
@github-actions github-actions Bot added linked issue not ready PR opened before its linked issue reached consensus CI:Linter failure The linter CI is failing on this PR labels Aug 13, 2026
@github-actions

Copy link
Copy Markdown

❌ Linting issues

This PR is introducing linting issues. Here's a summary of the issues. Note that you can avoid having linting issues by enabling pre-commit hooks. Instructions to enable them can be found here.

You can see the details of the linting issues under the lint job here


ruff check

ruff detected issues. Please run ruff check --fix --output-format=full locally, fix the remaining issues, and push the changes. Here you can see the detected issues. Note that the installed ruff version is ruff=0.12.2.

Details

sklearn/callback/_transport.py:22:48: F401 [*] `multiprocessing.connection.Connection` imported but unused
   |
20 | import weakref
21 | from collections import OrderedDict
22 | from multiprocessing.connection import Client, Connection, Listener
   |                                                ^^^^^^^^^^ F401
23 | from threading import Thread
24 | from typing import Callable, NamedTuple
   |
   = help: Remove unused import: `multiprocessing.connection.Connection`

Found 1 error.
[*] 1 fixable with the `--fix` option.

ruff format

ruff detected issues. Please run ruff format locally and push the changes. Here you can see the detected issues. Note that the installed ruff version is ruff=0.12.2.

Details

--- sklearn/callback/_transport.py
+++ sklearn/callback/_transport.py
@@ -60,8 +60,10 @@
 _listeners: dict[str, Listener] = {}
 _message_consumers: dict[str, Callable] = {}
 
+
 class _LRUConnectionCache(OrderedDict):
     """LRU cache for connections to avoid fd leaks."""
+
     def __init__(self, maxsize=16):
         super().__init__()
         self.maxsize = maxsize
@@ -85,6 +87,7 @@
             conn = self.pop(oldest)
             conn.close()
 
+
 # Worker-side cache of client connections back to the main-process listeners, keyed by
 # listener address. The first cross-process send opens a client. Subsequent sends to the
 # same listener reuse the cached connection.

1 file would be reformatted, 959 files already formatted

Generated for commit: 4b6bd87. Link to the linter CI: here

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

Labels

CI:Linter failure The linter CI is failing on this PR linked issue not ready PR opened before its linked issue reached consensus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Callback's _worker_connections cache grows too big

1 participant