Skip to content
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

Startup timeout fixes #2080

Merged
merged 2 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

* Sending startup crashes synchronously now uses a flexible timeout so that apps with slower startups don't ANR
[#2075](https://github.com/bugsnag/bugsnag-android/pull/2075)
[#2080](https://github.com/bugsnag/bugsnag-android/pull/2080)

## 6.7.0 (2024-08-08)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import java.util.concurrent.Future
import java.util.concurrent.RejectedExecutionException
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
import kotlin.math.max

/**
* Store and flush Event reports.
Expand Down Expand Up @@ -66,7 +65,15 @@ internal class EventStore(
// have blocked the main thread before this code is reached.
val currentStartupDuration =
SystemClock.elapsedRealtime() - ForegroundDetector.startupTime
val timeout = max(0, LAUNCH_CRASH_TIMEOUT_MS - currentStartupDuration)
var timeout = LAUNCH_CRASH_TIMEOUT_MS - currentStartupDuration

if (timeout <= 0) {
// if Bugsnag.start is called too long after Application.onCreate is expected to
// have returned, we use a full LAUNCH_CRASH_TIMEOUT_MS instead of a calculated one
// assuming that the app is already fully started
timeout = LAUNCH_CRASH_TIMEOUT_MS
}

future.get(timeout, TimeUnit.MILLISECONDS)
} catch (exc: InterruptedException) {
logger.d("Failed to send launch crash reports within timeout, continuing.", exc)
Expand Down
Loading