Skip to content

Commit

Permalink
fix(profiling): Handle non frame types in profiler (#1965)
Browse files Browse the repository at this point in the history
We've received report that occasionally, there's `AttributeError` on `f_back`.
It's unclear what exactly causes this issue because the source of the frame is
from a system libray. This avoids the `AttributeError` by wrapping the line in
question with a `try ... except ...`. And whenever it does encounter this error,
we should continue with what frames we have.
  • Loading branch information
Zylphrex committed Mar 20, 2023
1 parent 439b3f7 commit 871c437
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion sentry_sdk/profiler.py
Expand Up @@ -26,6 +26,7 @@
from sentry_sdk._compat import PY33, PY311
from sentry_sdk._types import TYPE_CHECKING
from sentry_sdk.utils import (
capture_internal_exception,
filename_for_module,
is_valid_sample_rate,
logger,
Expand Down Expand Up @@ -252,8 +253,16 @@ def extract_stack(
frames = deque(maxlen=max_stack_depth) # type: Deque[FrameType]

while frame is not None:
try:
f_back = frame.f_back
except AttributeError:
capture_internal_exception(sys.exc_info())
# For some reason, the frame we got isn't a `FrameType` and doesn't
# have a `f_back`. When this happens, we continue with any frames
# that we've managed to extract up to this point.
break
frames.append(frame)
frame = frame.f_back
frame = f_back

if prev_cache is None:
stack = tuple(extract_frame(frame, cwd) for frame in frames)
Expand Down

0 comments on commit 871c437

Please sign in to comment.