Skip to content

Commit

Permalink
fix: app starts hanging for 30s (#2140)
Browse files Browse the repository at this point in the history
* Update

* Update

* Add CHANGELOG

* Update comment

* Update CHANGELOG.md
  • Loading branch information
buenaflor authored Jul 8, 2024
1 parent c614bf9 commit f172c4d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## Unreleased

### Fixes

- App starts hanging for 30s ([#2140](https://github.com/getsentry/sentry-dart/pull/2140))
- Time out for app start info retrieval has been reduced to 10s
- If `autoAppStarts` is `false` and `setAppStartEnd` has not been called, the app start event processor will now return early instead of waiting for `getAppStartInfo` to finish

## 8.4.0-beta.1

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ class NativeAppStartEventProcessor implements EventProcessor {
return event;
}

final appStartInfo = await NativeAppStartIntegration.getAppStartInfo();

AppStartInfo? appStartInfo;
if (!options.autoAppStart) {
final appStartEnd = NativeAppStartIntegration.appStartEnd;
if (appStartEnd != null) {
appStartInfo = await NativeAppStartIntegration.getAppStartInfo();
appStartInfo?.end = appStartEnd;
} else {
// If autoAppStart is disabled and appStartEnd is not set, we can't add app starts
return event;
}
} else {
appStartInfo = await NativeAppStartIntegration.getAppStartInfo();
}

final measurement = appStartInfo?.toMeasurement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {
static bool didAddAppStartMeasurement = false;

/// Timeout duration to wait for the app start info to be fetched.
static const _timeoutDuration = Duration(seconds: 30);
static const _timeoutDuration = Duration(seconds: 10);

@visibleForTesting
static Duration get timeoutDuration => _timeoutDuration;

/// We filter out App starts more than 60s
static const _maxAppStartMillis = 60000;
Expand Down
33 changes: 30 additions & 3 deletions flutter/test/integrations/native_app_start_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,30 @@ void main() {
expect(enriched.spans.isEmpty, true);
});

test(
'does not trigger timeout if autoAppStart is false and setAppStartEnd is not called',
() async {
// setting a frame callback with a bigger timeout than our app start timeout so the timeout would theoretically be triggered
fixture = Fixture(
frameCallbackTimeout: NativeAppStartIntegration.timeoutDuration +
const Duration(seconds: 5));
fixture.options.autoAppStart = false;

await fixture.registerIntegration();

final tracer = fixture.createTracer();
final transaction = SentryTransaction(tracer);

final processor = fixture.options.eventProcessors.first;

final stopwatch = Stopwatch()..start();
await processor.apply(transaction, Hint()) as SentryTransaction;
stopwatch.stop();

expect(stopwatch.elapsed < NativeAppStartIntegration.timeoutDuration,
isTrue);
});

test(
'autoAppStart is false and appStartEnd is set adds app start measurement',
() async {
Expand Down Expand Up @@ -384,9 +408,12 @@ class Fixture extends IntegrationTestFixture<NativeAppStartIntegration> {
@override
MockHub get hub => super.hub as MockHub;

Fixture()
: super((binding) =>
NativeAppStartIntegration(binding, FakeFrameCallbackHandler())) {
Fixture({Duration? frameCallbackTimeout})
: super((binding) => NativeAppStartIntegration(
binding,
FakeFrameCallbackHandler(
finishAfterDuration: frameCallbackTimeout ??
const Duration(milliseconds: 50)))) {
NativeAppStartIntegration.reset();
hub = MockHub();
// ignore: invalid_use_of_internal_member
Expand Down

0 comments on commit f172c4d

Please sign in to comment.