Skip to content

tentacle: mgr: fix PyObject* refcounting in TTLCache and cleanup logic - #66482

Merged
batrick merged 5 commits into
ceph:tentaclefrom
NitzanMordhai:wip-74056-tentacle
Apr 6, 2026
Merged

batrick merged 5 commits into
ceph:tentaclefrom
NitzanMordhai:wip-74056-tentacle

Conversation

@NitzanMordhai

Copy link
Copy Markdown
Contributor

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

docs lgtm

@ljflores

ljflores commented Dec 8, 2025

Copy link
Copy Markdown
Member

@NitzanMordhai see #65245 (comment)

@NitzanMordhai

Copy link
Copy Markdown
Contributor Author

don't merge until #66571 merged

NitzanMordhai and others added 5 commits March 5, 2026 06:53
This patch introduces several improvements to the Prometheus module:

 - Introduces `HealthHistory._prune()` to drop stale and inactive health checks.
  Limits the in-memory healthcheck dict to a configurable max_entries (default 1000).
  TTL for stale entries is configurable via `healthcheck_history_stale_ttl` (default 3600s).

 - Refactors HealthHistory.check() to use a unified iteration over known and current checks,
  improving concurrency and minimizing redundant updates.

 - Use cherrypy.tools.gzip instead of manual gzip.compress() for cleaner
  HTTP compression with proper header handling and client negotiation.

 - Introduces new module options:
    - `healthcheck_history_max_entries`

 - Add proper error handling for CherryPy engine startup failures
 - Remove os._exit monkey patch in favor of proper exception handling
 - Remove manual Content-Type header setting (CherryPy handles automatically)

Fixes: https://tracker.ceph.com/issues/68989
Signed-off-by: Nitzan Mordechai <[email protected]>
(cherry picked from commit be28901)
Fix incorrect reference counting and memory retention behavior in TTLCache
when storing PyObject* values.
Previously, TTLCache::insert did not increment the reference count,
and `erase` / `clear` did not correctly decref the values, leading
to use-after-free or leaks depending on usage.

Changes:
- Move Py_INCREF from cacheable_get_python() to TTLCache::insert()
- Add `TTLCache::clear()` method for proper memory cleanup
- Ensure TTLCache::get() returns a new reference
- Fix misuse of std::move on c_str() in PyJSONFormatter

These changes prevent both memory leaks and use-after-free errors when
mgr modules use cached Python objects logic.

Fixes: https://tracker.ceph.com/issues/68989
Signed-off-by: Nitzan Mordechai <[email protected]>
(cherry picked from commit 7fadf6a)
The HealthHistory.check() method acquires the lock and then calls
HealthHistory.save(), which also tries to acquire the same lock.
With a regular Lock(), the same thread blocks trying to re-acquire it (deadlock).
Switch to RLock to allow nested acquisition by the same thread.
PR ceph#65245 added the locks.

Fixes: https://tracker.ceph.com/issues/74148
Signed-off-by: Nitzan Mordechai <[email protected]>
(cherry picked from commit 26394ca)
PR ceph#65245 drop the header set for standby module,
we should still have it.

Fixes: https://tracker.ceph.com/issues/74149
Signed-off-by: Nitzan Mordechai <[email protected]>
(cherry picked from commit 2ef12b2)
@NitzanMordhai

Copy link
Copy Markdown
Contributor Author

PR #66571 cherry-picked into that PR as well, removing DNM

@amathuria

Copy link
Copy Markdown
Contributor

@amathuria

Copy link
Copy Markdown
Contributor

jenkins test make check

1 similar comment
@NitzanMordhai

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@batrick
batrick merged commit 1911b5c into ceph:tentacle Apr 6, 2026
7 checks passed
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.

7 participants