Skip to content

mgr/rook: don't leak a watcher thread per orchestrator call - #70071

Merged
tchaikov merged 1 commit into
ceph:mainfrom
tchaikov:wip-rook-osd-watch-leak
Aug 27, 2026
Merged

tchaikov merged 1 commit into
ceph:mainfrom
tchaikov:wip-rook-osd-watch-leak

Conversation

@tchaikov

@tchaikov tchaikov commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

KubernetesResource spawns a watch thread on the first access to .items, and the thread runs until the watch stream ends. get_osds(), get_resource() and the device fetchers create a KubernetesResource per call, so one describe_service() leaks up to five threads, their HTTPS connections to the apiserver, and the item dicts the threads keep updating. Poll the orchestrator every few seconds and the active mgr accumulates threads until it is OOM-killed.

Filter the long-lived rook_pods watch in get_osds() the way describe_pods() does. Convert the other per-call sites to fetch_k8s_items(), a one-shot list call that spawns no watcher. KubernetesResource stays watch-only, for the three long-lived caches in RookCluster.

Fixes: https://tracker.ceph.com/issues/78589

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@tchaikov

tchaikov commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test rook e2e

1 similar comment
@tchaikov

tchaikov commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test rook e2e

@tchaikov

tchaikov commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@tchaikov

tchaikov commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@phlogistonjohn hi John, do you mind helping review this change?

@tchaikov

Copy link
Copy Markdown
Contributor Author

@travisn hi Travis, do you mind taking a look?

@travisn travisn 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.

LGTM, but I am not very familiar with the rook module internals. The key will be the testing. Can we get a ceph image with the change to test it out?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a resource leak in the mgr/rook orchestrator integration where short-lived KubernetesResource/KubernetesCustomResource instances can spawn watcher threads that outlive the caller, accumulating threads/connections and eventually causing OOM in long-running mgr daemons.

Changes:

  • Introduce fetch_k8s_items() as a one-shot “list” helper that does not start watcher threads.
  • Convert per-call fetch sites (device fetchers and get_resource()) to use fetch_k8s_items(), and update get_osds() to filter the long-lived rook_pods watch instead of creating new watchers.
  • Add a unit test covering fetch_k8s_items() return handling (object response vs dict response).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/pybind/mgr/rook/rook_cluster.py Adds fetch_k8s_items() and replaces per-call watcher usage to prevent thread/connection leaks; updates get_osds() to reuse the long-lived pod cache.
src/pybind/mgr/rook/tests/test_rook.py Adds a unit test for fetch_k8s_items() and its “no watcher thread” contract.

Comment thread src/pybind/mgr/rook/rook_cluster.py Resolved
Comment thread src/pybind/mgr/rook/tests/test_rook.py Resolved
KubernetesResource spawns a watch thread on the first access to
.items, and the thread runs until the watch stream ends. get_osds(),
get_resource() and the device fetchers create a KubernetesResource
per call, so one describe_service() leaks up to five threads, their
HTTPS connections to the apiserver, and the item dicts the threads
keep updating. Poll the orchestrator every few seconds and the active
mgr accumulates threads until it is OOM-killed.

Filter the long-lived rook_pods watch in get_osds() the way
describe_pods() does. Convert the other per-call sites to
fetch_k8s_items(), a one-shot list call that spawns no watcher.
KubernetesResource stays watch-only, for the three long-lived caches
in RookCluster.

Fixes: https://tracker.ceph.com/issues/78589
Signed-off-by: Kefu Chai <[email protected]>
@tchaikov
tchaikov force-pushed the wip-rook-osd-watch-leak branch from 4740720 to 0c468fe Compare July 23, 2026 02:31
@NitzanMordhai

Copy link
Copy Markdown
Contributor

@tchaikov do you know if we have any test coverage for that issue? Should we add something to cover it? i also not sure who is calling the test_rook.py tests in that change.

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@tchaikov how can we proceed with that pr ?

@tchaikov

tchaikov commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@tchaikov do you know if we have any test coverage for that issue? Should we add something to cover it? i also not sure who is calling the test_rook.py tests in that change.

@NitzanMordhai sorry that i missed your ping. test_rook.py is actually wired into our CI already. the call chain is like

src/pybind/mgr/CMakeLists.txt -> add_tox_test(mgr ;...) -> run-tox-mgr -> tox runs rook/tests/test_rook.py

i think we just need to run this change with a teuthology-basd test. something like qa/suites/orch/rook/smoke

@tchaikov tchaikov self-assigned this Aug 3, 2026
@NitzanMordhai

Copy link
Copy Markdown
Contributor

@tchaikov thank you for the explanation on that!

@tchaikov

tchaikov commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai thank you actually.

@NitzanMordhai

Copy link
Copy Markdown
Contributor

jenkins test rook e2e

@travisn

travisn commented Aug 7, 2026

Copy link
Copy Markdown
Member

How is the testing looking? Rook users would really appreciate having this fix in the next patch releases.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath1-testing-20260810.014116-main.

@NitzanMordhai

Copy link
Copy Markdown
Contributor

@travisn

travisn commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

@tchaikov To be clear, this PR is not a blocker, right? IIUC according to this comment that the memory leak would not be observed anymore since #70146 was merged and backported?

@tchaikov

Copy link
Copy Markdown
Contributor Author

@tchaikov To be clear, this PR is not a blocker, right? IIUC according to this comment that the memory leak would not be observed anymore since #70146 was merged and backported?

@travisn hi Travis, probably. as i cannot prove that #70146 address all leaks we observed. but yes, there are good chances that this change is not a blocker. but i'd prefer having all leak fixes merged in main, and backported.

@tchaikov
tchaikov requested a review from a team August 18, 2026 06:37
@tchaikov

Copy link
Copy Markdown
Contributor Author

@ceph/rook hello root maintainers, could you help review this change?

@travisn

travisn commented Aug 18, 2026

Copy link
Copy Markdown
Member

@tchaikov To be clear, this PR is not a blocker, right? IIUC according to this comment that the memory leak would not be observed anymore since #70146 was merged and backported?

@travisn hi Travis, probably. as i cannot prove that #70146 address all leaks we observed. but yes, there are good chances that this change is not a blocker. but i'd prefer having all leak fixes merged in main, and backported.

Sounds good, thanks for the confirmation that it is expected to largely be fixed already.

@ceph/rook hello root maintainers, could you help review this change?

Rook maintainers honestly are likely not help in reviews of the rook mgr module. Better if someone from @ceph/dashboard can take a look.

@NitzanMordhai
NitzanMordhai requested review from a team, AnuragRaut08 and syedali237 August 24, 2026 14:22
@NitzanMordhai

Copy link
Copy Markdown
Contributor

@nizamial09 can you also take a look?

@nizamial09 nizamial09 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.

overall lgtm on the code, thanks.

@tchaikov
tchaikov merged commit 478a38d into ceph:main Aug 27, 2026
9 checks passed
@tchaikov
tchaikov deleted the wip-rook-osd-watch-leak branch August 27, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants