From eb191548cffa43fb808ec6443dc3540881902137 Mon Sep 17 00:00:00 2001 From: Sebastian Lohff Date: Wed, 14 Jul 2021 12:37:49 +0200 Subject: [PATCH] Fix fo() backdoor command for non-class objects The backdoor command fo() uses isinstance() to check if an object is an instance of a class. This only works with objects that have a __class__ attribute, else an AttributeError is raised by isinstance(). This is seldomly the case, though if there is one such object fo() will cease to work. Therefore we need to protect us against this case by checking for a __class__ attribute before calling isinstance(). An example for an object without __class__ would be functools._lru_list_elem. Change-Id: Ia4c5cbdc249535d36f6e71f7b2a7359bc6fdf219 Closes-Bug: #1946072 --- oslo_service/eventlet_backdoor.py | 3 ++- .../notes/fix-find-object-in-backdoor-487bf78c4c502594.yaml | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-find-object-in-backdoor-487bf78c4c502594.yaml diff --git a/oslo_service/eventlet_backdoor.py b/oslo_service/eventlet_backdoor.py index 83908055..ada9a938 100644 --- a/oslo_service/eventlet_backdoor.py +++ b/oslo_service/eventlet_backdoor.py @@ -86,7 +86,8 @@ def _detailed_dump_frames(f, thread_index): def _find_objects(t): - return [o for o in gc.get_objects() if isinstance(o, t)] + return [o for o in gc.get_objects() + if hasattr(o, "__class__") and isinstance(o, t)] def _capture_profile(fname=''): diff --git a/releasenotes/notes/fix-find-object-in-backdoor-487bf78c4c502594.yaml b/releasenotes/notes/fix-find-object-in-backdoor-487bf78c4c502594.yaml new file mode 100644 index 00000000..31c088ad --- /dev/null +++ b/releasenotes/notes/fix-find-object-in-backdoor-487bf78c4c502594.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fix the backdoor helper method fo() to also work when there are objects + present in the current python instance that do not have a __class__ + attribute.