-
Notifications
You must be signed in to change notification settings - Fork 569
fix: Don't hang when capturing long stacktrace #4191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2fa2d46
fix: Don't hang when capturing long stacktrace
szokeasaurusrex a547e17
try reverting annotated stuff
szokeasaurusrex 309e6ef
Merge branch 'master' into szokeasaurusrex/recursion-depth
antonpirker 335e9a3
add explanation comments
szokeasaurusrex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,6 +77,15 @@ | |
| FALSY_ENV_VALUES = frozenset(("false", "f", "n", "no", "off", "0")) | ||
| TRUTHY_ENV_VALUES = frozenset(("true", "t", "y", "yes", "on", "1")) | ||
|
|
||
| MAX_STACK_FRAMES = 2000 | ||
| """Maximum number of stack frames to send to Sentry. | ||
|
|
||
| If we have more than this number of stack frames, we will stop processing | ||
| the stacktrace to avoid getting stuck in a long-lasting loop. This value | ||
| exceeds the default sys.getrecursionlimit() of 1000, so users will only | ||
| be affected by this limit if they have a custom recursion limit. | ||
| """ | ||
|
|
||
|
|
||
| def env_to_bool(value, *, strict=False): | ||
| # type: (Any, Optional[bool]) -> bool | None | ||
|
|
@@ -732,10 +741,23 @@ def single_exception_from_error_tuple( | |
| max_value_length=max_value_length, | ||
| custom_repr=custom_repr, | ||
| ) | ||
| for tb in iter_stacks(tb) | ||
| # Process at most MAX_STACK_FRAMES + 1 frames, to avoid hanging on | ||
| # processing a super-long stacktrace. | ||
| for tb, _ in zip(iter_stacks(tb), range(MAX_STACK_FRAMES + 1)) | ||
| ] # type: List[Dict[str, Any]] | ||
|
|
||
| if frames: | ||
| if len(frames) > MAX_STACK_FRAMES: | ||
| # If we have more frames than the limit, we remove the stacktrace completely. | ||
| # We don't trim the stacktrace here because we have not processed the whole | ||
| # thing (see above, we stop at MAX_STACK_FRAMES + 1). Normally, Relay would | ||
| # intelligently trim by removing frames in the middle of the stacktrace, but | ||
| # since we don't have the whole stacktrace, we can't do that. Instead, we | ||
| # drop the entire stacktrace. | ||
| exception_value["stacktrace"] = AnnotatedValue.removed_because_over_size_limit( | ||
| value=None | ||
| ) | ||
|
Comment on lines
+744
to
+758
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sentrivana what do you think about these comments?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm |
||
|
|
||
| elif frames: | ||
| if not full_stack: | ||
| new_frames = frames | ||
| else: | ||
|
|
@@ -941,7 +963,7 @@ def to_string(value): | |
|
|
||
|
|
||
| def iter_event_stacktraces(event): | ||
| # type: (Event) -> Iterator[Dict[str, Any]] | ||
| # type: (Event) -> Iterator[Annotated[Dict[str, Any]]] | ||
| if "stacktrace" in event: | ||
| yield event["stacktrace"] | ||
| if "threads" in event: | ||
|
|
@@ -950,20 +972,26 @@ def iter_event_stacktraces(event): | |
| yield thread["stacktrace"] | ||
| if "exception" in event: | ||
| for exception in event["exception"].get("values") or (): | ||
| if "stacktrace" in exception: | ||
| if isinstance(exception, dict) and "stacktrace" in exception: | ||
| yield exception["stacktrace"] | ||
|
|
||
|
|
||
| def iter_event_frames(event): | ||
| # type: (Event) -> Iterator[Dict[str, Any]] | ||
| for stacktrace in iter_event_stacktraces(event): | ||
| if isinstance(stacktrace, AnnotatedValue): | ||
| stacktrace = stacktrace.value or {} | ||
|
|
||
| for frame in stacktrace.get("frames") or (): | ||
| yield frame | ||
|
|
||
|
|
||
| def handle_in_app(event, in_app_exclude=None, in_app_include=None, project_root=None): | ||
| # type: (Event, Optional[List[str]], Optional[List[str]], Optional[str]) -> Event | ||
| for stacktrace in iter_event_stacktraces(event): | ||
| if isinstance(stacktrace, AnnotatedValue): | ||
| stacktrace = stacktrace.value or {} | ||
|
|
||
| set_in_app_in_frames( | ||
| stacktrace.get("frames"), | ||
| in_app_exclude=in_app_exclude, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.