Skip to content
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

Fix threading issues capturing log messages as breadcrumbs #559

Merged
merged 3 commits into from
May 23, 2024

Conversation

tustanivsky
Copy link
Collaborator

This PR addresses an issue which was discovered during the discussion around #514

Since log messages, asserts, ensures, etc. can come from different threads adding breadcrumbs automatically on such events can lead to undefined results due to the following reasons:

  • New breadcrumb UObject instance is created during garbage collection
  • Concurrent access to internal SentryScopeDesktop breadcrumbs storage

In order to resolve this breadcrumbs can now be captured without instancing any extra objects and some threading considerations were added.

Copy link
Contributor

@bitsandfoxes bitsandfoxes left a comment

Choose a reason for hiding this comment

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

Looks good!

Comment on lines +20 to +31
SentryScopeDesktop::SentryScopeDesktop(const SentryScopeDesktop& Scope)
{
Dist = Scope.Dist;
Environment = Scope.Environment;
FingerprintDesktop = Scope.FingerprintDesktop;
TagsDesktop = Scope.TagsDesktop;
ExtraDesktop = Scope.ExtraDesktop;
ContextsDesktop = Scope.ContextsDesktop;
BreadcrumbsDesktop = Scope.BreadcrumbsDesktop;
LevelDesktop = Scope.LevelDesktop;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this coming from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's essential to implement a custom copy constructor for the scope class after we've introduced a critical section member.

Since FCriticalSection disables its default copy constructor using the default mechanism for scope isn't possible and results into compilation errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL. Thanks!

SentryScopeDesktop::~SentryScopeDesktop()
{
}

void SentryScopeDesktop::AddBreadcrumb(USentryBreadcrumb* breadcrumb)
{
FScopeLock Lock(&CriticalSection);
Copy link
Contributor

Choose a reason for hiding this comment

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

That's neat, that it works like that.

@@ -12,6 +12,7 @@ class SentrySubsystemAndroid : public ISentrySubsystem
virtual bool IsEnabled() override;
virtual ESentryCrashedLastRun IsCrashedLastRun() override;
virtual void AddBreadcrumb(USentryBreadcrumb* breadcrumb) override;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're no longer using the "plain" AddBreadcrumb, do we need it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's still a part of the public API so I think we should leave it even though we're not using it internally anymore.

@tustanivsky tustanivsky merged commit ad9ced2 into main May 23, 2024
16 checks passed
@tustanivsky tustanivsky deleted the fix/breadcrumbs-threading branch May 23, 2024 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants