Skip to content

Commit

Permalink
Fix: Do not append threads that come from the EnvelopeFileObserver (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
marandaneto authored May 31, 2021
1 parent dbc59e2 commit fd64cc0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* Fix: Do not append threads that come from the EnvelopeFileObserver (#1501)
* Ref: Deprecate cacheDirSize and add maxCacheItems (#1499)

# 5.0.0-beta.6
Expand Down
18 changes: 15 additions & 3 deletions sentry/src/main/java/io/sentry/MainEventProcessor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry;

import io.sentry.hints.Cached;
import io.sentry.protocol.SentryException;
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
Expand Down Expand Up @@ -65,7 +66,7 @@ public final class MainEventProcessor implements EventProcessor {

if (shouldApplyScopeData(event, hint)) {
processNonCachedEvent(event);
setThreads(event);
setThreads(event, hint);
}

return event;
Expand Down Expand Up @@ -185,8 +186,8 @@ private void setExceptions(final @NotNull SentryEvent event) {
}
}

private void setThreads(final @NotNull SentryEvent event) {
if (event.getThreads() == null) {
private void setThreads(final @NotNull SentryEvent event, final @Nullable Object hint) {
if (event.getThreads() == null && !isCachedHint(hint)) {
// collecting threadIds that came from the exception mechanism, so we can mark threads as
// crashed properly
List<Long> mechanismThreadIds = null;
Expand Down Expand Up @@ -214,4 +215,15 @@ private void setThreads(final @NotNull SentryEvent event) {
}
}
}

/**
* If the event has a Cached Hint, it means that it came from the EnvelopeFileObserver. We don't
* want to append this thread to the event.
*
* @param hint the Hint
* @return true if Cached or false otherwise
*/
private boolean isCachedHint(final @Nullable Object hint) {
return (hint instanceof Cached);
}
}
17 changes: 13 additions & 4 deletions sentry/src/test/java/io/sentry/MainEventProcessorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,14 @@ class MainEventProcessorTest {
val sut = fixture.getSut()
val crashedThread = Thread.currentThread()
var event = generateCrashedEvent(crashedThread)
event = sut.process(event, mock<CustomCachedApplyScopeDataHint>())
event = sut.process(event, CustomCachedApplyScopeDataHint())

assertEquals("release", event.release)
assertEquals("environment", event.environment)
assertEquals("dist", event.dist)
assertEquals("server", event.serverName)
assertNotNull(event.threads) {
assertTrue(it.first { t -> t.id == crashedThread.id }.isCrashed == true)
}
// threads are special case if its a Cached hint
assertNull(event.threads)
}

@Test
Expand Down Expand Up @@ -394,6 +393,16 @@ class MainEventProcessorTest {
assertNotNull(transaction.user)
}

@Test
fun `when event has Cached hint, threads should not be set`() {
val sut = fixture.getSut()

var event = SentryEvent()
event = sut.process(event, CustomCachedApplyScopeDataHint())

assertNull(event.threads)
}

private fun generateCrashedEvent(crashedThread: Thread = Thread.currentThread()) = SentryEvent().apply {
val mockThrowable = mock<Throwable>()
val actualThrowable = UncaughtExceptionHandlerIntegration.getUnhandledThrowable(crashedThread, mockThrowable)
Expand Down

0 comments on commit fd64cc0

Please sign in to comment.