-
-
Notifications
You must be signed in to change notification settings - Fork 444
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 crash on double SDK init #2679
Changes from 2 commits
960fd20
6af6003
2914bec
7e1be4f
997f4e3
c0607ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.sentry.uitest.android | ||
|
||
import androidx.lifecycle.Lifecycle | ||
import androidx.test.core.app.launchActivity | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.sentry.Sentry | ||
import io.sentry.android.core.SentryAndroidOptions | ||
import org.junit.runner.RunWith | ||
import kotlin.test.Test | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class SdkInitTests : BaseUiTest() { | ||
|
||
@Test | ||
fun doubleInitDoesNotThrow() { | ||
initSentry(false) { options: SentryAndroidOptions -> | ||
options.tracesSampleRate = 1.0 | ||
options.profilesSampleRate = 1.0 | ||
} | ||
val transaction = Sentry.startTransaction("e2etests", "testInit") | ||
val sampleScenario = launchActivity<EmptyActivity>() | ||
initSentry(false) { options: SentryAndroidOptions -> | ||
options.tracesSampleRate = 1.0 | ||
options.profilesSampleRate = 1.0 | ||
} | ||
transaction.finish() | ||
sampleScenario.moveToState(Lifecycle.State.DESTROYED) | ||
val transaction2 = Sentry.startTransaction("e2etests", "testInit") | ||
transaction2.finish() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,21 @@ public void close() { | |
((Closeable) integration).close(); | ||
} | ||
} | ||
|
||
withScope( | ||
scope -> { | ||
ITransaction transaction = scope.getTransaction(); | ||
if (transaction != null) { | ||
for (Span span : transaction.getSpans()) { | ||
span.setSpanFinishedCallback(null); | ||
span.finish(SpanStatus.CANCELLED); | ||
} | ||
transaction.finish(SpanStatus.CANCELLED); | ||
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. Is it right to close the current transaction? 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. I think it makes sense, especially for Mobile. @adinauer does this seem right for you as well? 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. we are dropping canceling the transaction for the moment, as we have to be careful on the backend use case.
stefanosiano marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
scope.clear(); | ||
}); | ||
options.getTransactionProfiler().close(); | ||
options.getTransactionPerformanceCollector().close(); | ||
options.getExecutorService().close(options.getShutdownTimeoutMillis()); | ||
|
||
// Close the top-most client | ||
|
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.
Nice! I think there's one more test to cover which would fail right now: Initializing the SDK with the same options twice.
I guess the solution here would be to re-init the executor-service in
.init()