Skip to content

squid: mgr: fix PyObject* refcounting in TTLCache and cleanup logic - #66483

Merged
batrick merged 5 commits into
ceph:squidfrom
NitzanMordhai:wip-74057-squid
Jul 27, 2026
Merged

batrick merged 5 commits into
ceph:squidfrom
NitzanMordhai:wip-74057-squid

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

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

LGTM with a nit: the differences from cherry-picking need to be explicitly mentioned the commit description (Conflicts).

Comment thread src/pybind/mgr/prometheus/module.py Outdated
import re
import threading
import time
import enum
from collections import namedtuple
from collections import OrderedDict
from tempfile import NamedTemporaryFile

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.

I think it's a difference from main which was including tempfile already.

import re
import threading
import time
import enum
from collections import namedtuple
from collections import OrderedDict

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.

Oh, so the discrepancy between main and the backport has been tackled not by adding the Conflict section but rather by squeezing the diff. Fine!

@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

@batrick
batrick marked this pull request as draft February 18, 2026 15:42
@batrick

batrick commented Feb 18, 2026

Copy link
Copy Markdown
Member

Converting to draft based on #66483 (comment)

@github-actions

github-actions Bot commented Mar 5, 2026

Copy link
Copy Markdown

This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved

@NitzanMordhai
NitzanMordhai marked this pull request as ready for review March 5, 2026 08:24
@dvanders

Copy link
Copy Markdown
Contributor

@NitzanMordhai is this blocked on something?

@kshtsk

kshtsk commented May 13, 2026

Copy link
Copy Markdown
Contributor

jenkins test make check

@kshtsk

kshtsk commented May 13, 2026

Copy link
Copy Markdown
Contributor

jenkins test api

@kshtsk

kshtsk commented May 13, 2026

Copy link
Copy Markdown
Contributor

jenkins test dashboard

@batrick batrick added the releng-audit-fail Release engineering: failed backport verification audit. label May 14, 2026
@github-actions github-actions Bot removed the releng-audit-fail Release engineering: failed backport verification audit. label May 14, 2026
github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions Bot added the releng-audit-fail Release engineering: failed backport verification audit. label May 14, 2026
@NitzanMordhai

Copy link
Copy Markdown
Contributor Author

@NitzanMordhai is this blocked on something?

@dvanders No, now we can continue with it

NitzanMordhai and others added 5 commits May 18, 2026 13:43
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

@NitzanMordhai

Copy link
Copy Markdown
Contributor Author

jenkins test docs

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ceph Release Engineering Audit Report

Commit Parity Visualizer

BACKPORT PR #66483 SOURCE PR SOURCE STATUS
848874c mgr/prometheus: prune stale health checks, compress output PR #65245 be28901 mgr/prometheus: prune stale health checks, compress output
deb702e mgr/TTLCache: fix PyObject* lifetime management and cleanup logic 7fadf6a mgr/TTLCache: fix PyObject* lifetime management and cleanup logic
10ef056 mgr/prometheus: Use RLock to fix deadlock in HealthHistory PR #66571 26394ca mgr/prometheus: Use RLock to fix deadlock in HealthHistory
8b01148 mgr/prometheus: metrics header for standby module 2ef12b2 mgr/prometheus: metrics header for standby module
5bdeb77 mgr/prometheus/test_module: Adding unit-test for new classes e3de8c9 mgr/prometheus/test_module: Adding unit-test for new classes

Automated Backport Parity Review - Cherry-Pick Conflicts / Deviations

⚠️ WARNING: Cherry-pick conflicts or deviations were found that require component lead review.

A conflict or deviation was detected during the simulation of this backport. The code in this PR does not match a clean cherry-pick of the upstream commits.

This does not necessarily indicate an issue but a maintainer should review.

**Click to expand conflict summaries.**

Deviation in Backport 848874c (cherry-pick of be28901)

Affected File(s)

Range Diff

Click to expand
--- Original (be28901f)
+++ Backport (848874c8)
@@ -21,3 +21,4 @@
 
 Fixes: https://tracker.ceph.com/issues/68989
 Signed-off-by: Nitzan Mordechai <[email protected]>
+(cherry picked from commit be28901f361cadcf6bf993276d71f3a79beaae4f)

================================================================================
RANGE DIFF
================================================================================

1:  be28901f361 ! 1:  848874c8e86 mgr/prometheus: prune stale health checks, compress output
    @@ Commit message
     
         Fixes: https://tracker.ceph.com/issues/68989
         Signed-off-by: Nitzan Mordechai <[email protected]>
    +    (cherry picked from commit be28901f361cadcf6bf993276d71f3a79beaae4f)
     
      ## doc/mgr/prometheus.rst ##
     @@ doc/mgr/prometheus.rst: Configuration
    @@ src/pybind/mgr/prometheus/module.py: import yaml
      import enum
      from collections import namedtuple
     +from collections import OrderedDict
    - from tempfile import NamedTemporaryFile
      
      from mgr_module import CLIReadCommand, MgrModule, MgrStandbyModule, PG_STATES, Option, ServiceInfoT, HandleCommandResult, CLIWriteCommand
    -@@ src/pybind/mgr/prometheus/module.py: from mgr_util import get_default_addr, profile_method, build_url
    + from mgr_util import get_default_addr, profile_method, build_url
      from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
      from rbd import RBD
      
    --from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO
    -+from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO, TypeVar, Generic
    +-from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable
    ++from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, TypeVar, Generic
    + 
      LabelValues = Tuple[str, ...]
      Number = Union[int, float]
    - MetricValue = Dict[LabelValues, Number]
     @@ src/pybind/mgr/prometheus/module.py: MetricValue = Dict[LabelValues, Number]
      
      DEFAULT_PORT = 9283

Deviation in Backport 10ef056 (cherry-pick of 26394ca)

Affected File(s)

Range Diff

Click to expand
--- Original (26394ca0)
+++ Backport (10ef0564)
@@ -8,3 +8,4 @@
 
 Fixes: https://tracker.ceph.com/issues/74148
 Signed-off-by: Nitzan Mordechai <[email protected]>
+(cherry picked from commit 26394ca06981e87ec7aee75b8467817afa330ba6)

================================================================================
RANGE DIFF
================================================================================

1:  26394ca0698 ! 1:  10ef0564977 mgr/prometheus: Use RLock to fix deadlock in HealthHistory
    @@ Commit message
     
         Fixes: https://tracker.ceph.com/issues/74148
         Signed-off-by: Nitzan Mordechai <[email protected]>
    +    (cherry picked from commit 26394ca06981e87ec7aee75b8467817afa330ba6)
     
      ## src/pybind/mgr/prometheus/module.py ##
    -@@ src/pybind/mgr/prometheus/module.py: from mgr_util import get_default_addr, profile_method, build_url, test_port_allo
    +@@ src/pybind/mgr/prometheus/module.py: from mgr_util import get_default_addr, profile_method, build_url
      from orchestrator import OrchestratorClientMixin, raise_if_exception, OrchestratorError
      from rbd import RBD
      
    --from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO, TypeVar, Generic
    -+from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, IO, TypeVar, Iterator
    +-from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, TypeVar, Generic
    +-
    ++from typing import DefaultDict, Optional, Dict, Any, Set, cast, Tuple, Union, List, Callable, TypeVar, Iterator
      LabelValues = Tuple[str, ...]
      Number = Union[int, float]
      MetricValue = Dict[LabelValues, Number]
    @@ src/pybind/mgr/prometheus/module.py: class HealthHistory:
          def __init__(self, mgr: MgrModule):
              self.mgr = mgr
     -        self.lock = threading.Lock()
    -+        self.lock = threading.RLock()
    -         self.max_entries = cast(int, self.mgr.get_localized_module_option('healthcheck_history_max_entries', 1000))
    +-        self.max_entries = cast(int, self.mgr.get_localized_module_option('healthcheck_history_max_entries', 1000))
     -        self.healthcheck: LRUCacheDict[str, HealthCheckEvent] = LRUCacheDict(maxsize=self.max_entries)
    -+        self.healthcheck: ThreadSafeLRUCacheDict[str, HealthCheckEvent] = ThreadSafeLRUCacheDict(maxsize=self.max_entries)
    ++        self.lock = threading.RLock()
    ++        self.max_entries = cast(int, self.mgr.get_localized_module_option(
    ++            'healthcheck_history_max_entries', 1000))
    ++        self.healthcheck: ThreadSafeLRUCacheDict[str, HealthCheckEvent] = ThreadSafeLRUCacheDict(
    ++            maxsize=self.max_entries)
              self._load()
      
          def _load(self) -> None:
    @@ src/pybind/mgr/prometheus/module.py: class Module(MgrModule, OrchestratorClientM
              for name, info in self.health_history.healthcheck.items():
                  v = 1 if info.active else 0
                  self.metrics['health_detail'].set(
    +@@ src/pybind/mgr/prometheus/module.py: class Module(MgrModule, OrchestratorClientMixin):
    +             host = cast(str, server.get('hostname', ''))
    +             for service in cast(List[ServiceInfoT], server.get('services', [])):
    +                 ret.update({(service['id'], service['type']): (host,
    +-                                                               service.get('ceph_version', 'unknown'),
    ++                                                               service.get(
    ++                                                                   'ceph_version', 'unknown'),
    +                                                                service.get('name', ''))})
    +         return ret
    + 

How to proceed:

  • Authors (Genuine Conflicts): If this is a genuine conflict requiring manual resolution, ensure your resolution is correct. You must explain the conflict resolution in the commit message (e.g., leave the standard Git Conflicts: block intact) and include an explanation for changes.
  • Authors (Need Help?): Reach out to the Component Lead for technical guidance on complex code conflicts.
  • Component Leads (Review): Please review the Range Diff(s) above to verify the author's manual conflict resolution is correct for this release branch. If the deviation is intentional, documented, and approved then the component lead or @ceph/ceph-release-manager can bypass this check by commenting /audit override.

Be familiar with the rules and guidelines for writing backports.


🛟 Need Help?

If you need technical help resolving these issues, please consult with the Component Lead. If you need administrative overrides, please see the #ceph-upstream-releases channel on Slack and request a review from the @ceph/ceph-release-manager.

📋 Component Lead / Release Manager

To override the audit failure, apply releng-audit-override label or comment /audit override.


⚠️ Note: Automated audit checks will be suspended on future pushes to prevent comment spam while you work.

When you are ready for a new audit, please remove the releng-audit-fail label or comment /audit retest.

View workflow run

@github-actions

Copy link
Copy Markdown

✅ Audit Override Applied by @batrick.

View workflow run

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

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

9 participants