-
-
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
Conversation
closing the hub will close the profiler and the performance collector added ui test for double init
span.setSpanFinishedCallback(null); | ||
span.finish(SpanStatus.CANCELLED); | ||
} | ||
transaction.finish(SpanStatus.CANCELLED); |
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.
Is it right to close the current transaction?
Also, should we think about closing any other manual transaction started by the user?
Transactions keep a reference to the old options, and so to the executor service, possibly leading to a crash. In reality all calls are now wrapped in try catch blocks, so it's a non-issue.
It's more to understand if it makes sense to stop the transactions from a end user perspective
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.
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 comment
The 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.
Worst case we will show some errors in the logs, pointing at a possible Sentry.close()
previous call.
In another pr we will reevaluate cancelling the current transactions.
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
33c80c7 | 331.94 ms | 370.54 ms | 38.60 ms |
d81684e | 235.73 ms | 328.76 ms | 93.03 ms |
17ab223 | 427.65 ms | 484.31 ms | 56.65 ms |
33c80c7 | 318.88 ms | 348.14 ms | 29.26 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
33c80c7 | 1.73 MiB | 2.26 MiB | 551.46 KiB |
d81684e | 1.73 MiB | 2.26 MiB | 547.78 KiB |
17ab223 | 1.73 MiB | 2.34 MiB | 626.85 KiB |
33c80c7 | 1.73 MiB | 2.26 MiB | 551.46 KiB |
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.
Looking good already, please have a look at my comments!
span.setSpanFinishedCallback(null); | ||
span.finish(SpanStatus.CANCELLED); | ||
} | ||
transaction.finish(SpanStatus.CANCELLED); |
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.
I think it makes sense, especially for Mobile. @adinauer does this seem right for you as well?
transaction.finish() | ||
sampleScenario.moveToState(Lifecycle.State.DESTROYED) | ||
val transaction2 = Sentry.startTransaction("e2etests", "testInit") | ||
transaction2.finish() |
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.
val options = {}
Sentry.init(options)
Sentry.close()
Sentry.init(options)
I guess the solution here would be to re-init the executor-service in .init()
profiling is now stopped on executorService exceptions transaction bound to the scope is not cancelled automatically anymore on Sentry.close() ISentryExecutorService is re-init in Sentry.init if it was shutdown
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #2679 +/- ##
============================================
+ Coverage 81.28% 81.33% +0.04%
- Complexity 4263 4271 +8
============================================
Files 337 337
Lines 15759 15795 +36
Branches 2080 2083 +3
============================================
+ Hits 12810 12847 +37
+ Misses 2128 2125 -3
- Partials 821 823 +2
☔ View full report in Codecov by Sentry. |
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, looks good to me!
@@ -339,6 +339,10 @@ public void close() { | |||
((Closeable) integration).close(); | |||
} | |||
} | |||
|
|||
withScope(scope -> scope.clear()); |
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.
late to the party, but this is not gonna do much, because withScope
will duplicate the scope, and then we're trying to clear the duplicated scope, but the main scope stays untouched. This should be changed to configureScope
. I think we need a custom lint rule to never use withScope on mobile 😅 this is the second time we introduced something like this (this one is not as severe though).
📜 Description
all calls to ISentryExecutorService are now wrapped in a try catch block
closing the hub will close the profiler and the performance collector
💡 Motivation and Context
Calling
init()
multiple times closes any previous instance of the SDK.After closing, any call to the executor service which was previously scheduled resulted in a crash due to
RejectedExecutionException
.Fixes #2493
💚 How did you test it?
Unit and ui test
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps