Skip to content

Commit f172c4d

Browse files
authored
fix: app starts hanging for 30s (#2140)
* Update * Update * Add CHANGELOG * Update comment * Update CHANGELOG.md
1 parent c614bf9 commit f172c4d

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- App starts hanging for 30s ([#2140](https://github.com/getsentry/sentry-dart/pull/2140))
8+
- Time out for app start info retrieval has been reduced to 10s
9+
- 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
10+
311
## 8.4.0-beta.1
412

513
### Features

flutter/lib/src/event_processor/native_app_start_event_processor.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ class NativeAppStartEventProcessor implements EventProcessor {
2424
return event;
2525
}
2626

27-
final appStartInfo = await NativeAppStartIntegration.getAppStartInfo();
28-
27+
AppStartInfo? appStartInfo;
2928
if (!options.autoAppStart) {
3029
final appStartEnd = NativeAppStartIntegration.appStartEnd;
3130
if (appStartEnd != null) {
31+
appStartInfo = await NativeAppStartIntegration.getAppStartInfo();
3232
appStartInfo?.end = appStartEnd;
3333
} else {
3434
// If autoAppStart is disabled and appStartEnd is not set, we can't add app starts
3535
return event;
3636
}
37+
} else {
38+
appStartInfo = await NativeAppStartIntegration.getAppStartInfo();
3739
}
3840

3941
final measurement = appStartInfo?.toMeasurement();

flutter/lib/src/integrations/native_app_start_integration.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ class NativeAppStartIntegration extends Integration<SentryFlutterOptions> {
3434
static bool didAddAppStartMeasurement = false;
3535

3636
/// Timeout duration to wait for the app start info to be fetched.
37-
static const _timeoutDuration = Duration(seconds: 30);
37+
static const _timeoutDuration = Duration(seconds: 10);
38+
39+
@visibleForTesting
40+
static Duration get timeoutDuration => _timeoutDuration;
3841

3942
/// We filter out App starts more than 60s
4043
static const _maxAppStartMillis = 60000;

flutter/test/integrations/native_app_start_integration_test.dart

+30-3
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,30 @@ void main() {
146146
expect(enriched.spans.isEmpty, true);
147147
});
148148

149+
test(
150+
'does not trigger timeout if autoAppStart is false and setAppStartEnd is not called',
151+
() async {
152+
// setting a frame callback with a bigger timeout than our app start timeout so the timeout would theoretically be triggered
153+
fixture = Fixture(
154+
frameCallbackTimeout: NativeAppStartIntegration.timeoutDuration +
155+
const Duration(seconds: 5));
156+
fixture.options.autoAppStart = false;
157+
158+
await fixture.registerIntegration();
159+
160+
final tracer = fixture.createTracer();
161+
final transaction = SentryTransaction(tracer);
162+
163+
final processor = fixture.options.eventProcessors.first;
164+
165+
final stopwatch = Stopwatch()..start();
166+
await processor.apply(transaction, Hint()) as SentryTransaction;
167+
stopwatch.stop();
168+
169+
expect(stopwatch.elapsed < NativeAppStartIntegration.timeoutDuration,
170+
isTrue);
171+
});
172+
149173
test(
150174
'autoAppStart is false and appStartEnd is set adds app start measurement',
151175
() async {
@@ -384,9 +408,12 @@ class Fixture extends IntegrationTestFixture<NativeAppStartIntegration> {
384408
@override
385409
MockHub get hub => super.hub as MockHub;
386410

387-
Fixture()
388-
: super((binding) =>
389-
NativeAppStartIntegration(binding, FakeFrameCallbackHandler())) {
411+
Fixture({Duration? frameCallbackTimeout})
412+
: super((binding) => NativeAppStartIntegration(
413+
binding,
414+
FakeFrameCallbackHandler(
415+
finishAfterDuration: frameCallbackTimeout ??
416+
const Duration(milliseconds: 50)))) {
390417
NativeAppStartIntegration.reset();
391418
hub = MockHub();
392419
// ignore: invalid_use_of_internal_member

0 commit comments

Comments
 (0)