-
-
Notifications
You must be signed in to change notification settings - Fork 459
feat(android-distribution): Run checkForUpdate on background thread (EME-413) #4811
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
base: main
Are you sure you want to change the base?
Conversation
…EME-413) Implement async version of checkForUpdate that runs on a background thread instead of blocking the calling thread. The callback is invoked on the background thread, allowing callers to dispatch to main thread if needed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
onResult.onResult(result) | ||
Thread { | ||
val result = checkForUpdateBlocking() | ||
onResult.onResult(result) |
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.
Potential bug: The onResult
callback is not wrapped in a try-catch block, which could lead to an app crash if the user's implementation throws an exception.
-
Description: The
onResult.onResult(result)
call is executed on a background thread without any exception handling. If the user-providedonResult
callback throws an exception, it will be uncaught on that thread, likely causing the entire application to crash. This is inconsistent with other parts of the SDK, such as the handling ofOnDiscardCallback
, where user-provided callbacks are defensively wrapped in atry-catch
block to prevent such failures. -
Suggested fix: Wrap the
onResult.onResult(result)
call within atry-catch (Throwable e)
block. Log any caught exceptions using the provided logger, similar to the pattern used for other user callbacks in the SDK to protect the app from crashing.
severity: 0.75, confidence: 0.95
Did we get this right? 👍 / 👎 to inform future reviews.
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.
This is a good point but we should just crash here.
Performance metrics 🚀
|
Revision | Plain | With Sentry | Diff |
---|---|---|---|
23d6b12 | 354.10 ms | 408.38 ms | 54.28 ms |
96449e8 | 361.30 ms | 423.39 ms | 62.09 ms |
9fbb112 | 404.51 ms | 475.65 ms | 71.14 ms |
ee747ae | 396.82 ms | 441.67 ms | 44.86 ms |
f634d01 | 375.06 ms | 420.04 ms | 44.98 ms |
14ff5ee | 419.75 ms | 495.73 ms | 75.98 ms |
ee747ae | 400.46 ms | 423.61 ms | 23.15 ms |
806307f | 357.85 ms | 424.64 ms | 66.79 ms |
b750b96 | 421.25 ms | 444.09 ms | 22.84 ms |
c8125f3 | 383.82 ms | 441.66 ms | 57.84 ms |
App size
Revision | Plain | With Sentry | Diff |
---|---|---|---|
23d6b12 | 1.58 MiB | 2.10 MiB | 532.31 KiB |
96449e8 | 1.58 MiB | 2.11 MiB | 539.35 KiB |
9fbb112 | 1.58 MiB | 2.11 MiB | 539.18 KiB |
ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
f634d01 | 1.58 MiB | 2.10 MiB | 533.40 KiB |
14ff5ee | 1.58 MiB | 2.10 MiB | 535.08 KiB |
ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
806307f | 1.58 MiB | 2.10 MiB | 533.42 KiB |
b750b96 | 1.58 MiB | 2.10 MiB | 533.20 KiB |
c8125f3 | 1.58 MiB | 2.10 MiB | 532.32 KiB |
onResult.onResult(result) | ||
Thread { | ||
val result = checkForUpdateBlocking() | ||
onResult.onResult(result) |
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 ideally we should:
- not create a new thread for this
- avoid a call back if we can (people will not read the comment and be confused when this crashes)
Looks like we already have some sort of common executor service which is used in the codebase and returns a future. Doesn't seem like it's Android aware (with Handlers / Loopers) but seems used from Android code.
final Future<Void> futureTask = executorService.submit(hostRetriever); public @NotNull <T> Future<T> submit(final @NotNull Callable<T> callable) - https://developer.android.com/develop/background-work/background-tasks/asynchronous/java-threads#use-handlers
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.
To finish the thought XD : I think we should use that existing thing if at all possible, if not we should create something similar we can use. Spawning a new thread for each call will come back to bite us at some point.
Summary
Implements the async version of
checkForUpdate()
to run on a background thread instead of blocking the calling thread.Thread
Changes
DistributionIntegration.checkForUpdate()
to spawn a background thread#skip-changelog
Fixes EME-413
🤖 Generated with Claude Code