-
-
Notifications
You must be signed in to change notification settings - Fork 426
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
Deduplicate events happening in multiple threads simultaneously #2845
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
63adf4e
Deduplicate events happening in multiple threads simultaneously
romtsn 704b93b
Merge branch 'main' into rz/fix/dedupe-ooms
romtsn aac6bc8
Changelog
romtsn 4a94969
Only deduplicate events coming from our ExceptionHandler and only on …
romtsn d2d735a
Merge branch 'main' into rz/fix/dedupe-ooms
romtsn 9f0d9d5
Changelog
romtsn 9bc6ed1
Changelog
romtsn File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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
1 change: 1 addition & 0 deletions
1
sentry-samples/sentry-samples-android/src/main/res/values/strings.xml
This file contains 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 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
65 changes: 65 additions & 0 deletions
65
sentry/src/main/java/io/sentry/DeduplicateMultithreadedEventProcessor.java
This file contains 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.sentry; | ||
|
||
import io.sentry.hints.EventDropReason; | ||
import io.sentry.protocol.SentryException; | ||
import io.sentry.util.HintUtils; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* An event processor that deduplicates crash events of the same type that are simultaneously from | ||
* multiple threads. This can be the case for OutOfMemory errors or CursorWindowAllocationException, | ||
* basically any error related to allocating memory when it's low. | ||
*/ | ||
public final class DeduplicateMultithreadedEventProcessor implements EventProcessor { | ||
|
||
private final @NotNull Map<String, Long> processedEvents = | ||
Collections.synchronizedMap(new HashMap<>()); | ||
|
||
private final @NotNull SentryOptions options; | ||
|
||
public DeduplicateMultithreadedEventProcessor(final @NotNull SentryOptions options) { | ||
this.options = options; | ||
} | ||
|
||
@Override | ||
public @Nullable SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { | ||
if (!HintUtils.hasType(hint, UncaughtExceptionHandlerIntegration.UncaughtExceptionHint.class)) { | ||
// only dedupe crashes coming from our exception handler, because custom errors/crashes might | ||
// be sent on purpose | ||
return event; | ||
} | ||
|
||
final SentryException exception = event.getUnhandledException(); | ||
if (exception == null) { | ||
return event; | ||
} | ||
|
||
final String type = exception.getType(); | ||
if (type == null) { | ||
return event; | ||
} | ||
|
||
final Long currentEventTid = exception.getThreadId(); | ||
if (currentEventTid == null) { | ||
return event; | ||
} | ||
|
||
final Long tid = processedEvents.get(type); | ||
if (tid != null && !tid.equals(currentEventTid)) { | ||
options | ||
.getLogger() | ||
.log( | ||
SentryLevel.INFO, | ||
"Event %s has been dropped due to multi-threaded deduplication", | ||
event.getEventId()); | ||
HintUtils.setEventDropReason(hint, EventDropReason.MULTITHREADED_DEDUPLICATION); | ||
return null; | ||
} | ||
processedEvents.put(type, currentEventTid); | ||
return event; | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.sentry.hints; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** A reason for which an event was dropped, used for (not to confuse with ClientReports) */ | ||
@ApiStatus.Internal | ||
public enum EventDropReason { | ||
MULTITHREADED_DEDUPLICATION | ||
} |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change is needed because otherwise the other crashing threads will not hold a lock anymore and will crash the app immediately, not giving a chance to persist the crash that was the first one (the one which we're going to deduplicate).