Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions aws_xray_sdk/core/utils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def metadata_to_dict(obj):
return metadata
else:
return obj
except Exception:
log.exception("Failed to convert metadata to dict")
except Exception as e:
import pprint
log.warning("Failed to convert metadata to dict:\n%s", pprint.pformat(getattr(e, "args", None)))
return {}
20 changes: 20 additions & 0 deletions tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
from aws_xray_sdk.core.recorder import AWSXRayRecorder
from aws_xray_sdk.core.emitters.udp_emitter import UDPEmitter
from aws_xray_sdk.core.sampling.sampler import DefaultSampler
from aws_xray_sdk.core.utils.conversion import metadata_to_dict


class CircularReferenceClass:
"""Test class that can create circular references"""
def __init__(self, name):
self.name = name
self.ref = None


class StubbedEmitter(UDPEmitter):
Expand Down Expand Up @@ -99,3 +107,15 @@ def _search_entity_by_annotation(entity, key, value):
if result is not None:
return result
return None


def test_metadata_to_dict_self_reference():
"""Test that self-referencing objects don't cause stack overflow"""
obj = CircularReferenceClass("self_ref")
obj.ref = obj # Self reference

# This should not cause stack overflow
result = metadata_to_dict(obj)

# The function should handle the self reference gracefully
assert isinstance(result, dict)
Loading