Skip to content

Commit bb693d7

Browse files
[stable] [flutter_tools] Fix crash in symbolize command on stream error (#191605)
### Issue Link: #191205 ### Impact Description: When running `flutter symbolize` on an obfuscated stack trace, if the underlying process output stream completes or encounters an error while a `Completer` is already resolved, `Symbolizer` crashes unexpectedly with `StateError: Bad state: Future already completed`. This causes the CLI to exit abruptly during stack deobfuscation and crash report generation. ### Changelog Description: [flutter/191205] Prevent `StateError: Bad state: Future already completed` in `Symbolizer` by checking `completer.isCompleted` when handling stream errors and completions during stack symbolization. ### Workaround: Manually deobfuscate stack traces using standalone `addr2line` / `atos` / `llvm-symbolizer` tools. ### Risk: ### Test Coverage: ### Validation Steps: 1. Generate an obfuscated stack trace using `flutter build apk --obfuscate --split-debug-info=...`. 2. Run `flutter symbolize --debug-info=<symbols-file> -i <stacktrace.txt>`. 3. Verify that `flutter symbolize` processes the stack trace without throwing `StateError: Bad state: Future already completed`.
1 parent b3bc058 commit bb693d7

2 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎packages/flutter_tools/lib/src/commands/symbolize.dart‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,12 +316,13 @@ class DwarfSymbolizationService {
316316
},
317317
onDone: onDone.complete,
318318
onError: onDone.completeError,
319+
cancelOnError: true,
319320
);
320321

321322
try {
322323
await onDone.future;
323324
await output.close();
324-
} on Exception catch (err) {
325+
} on Object catch (err) {
325326
throwToolExit('Failed to symbolize stack trace:\n $err');
326327
}
327328
}

‎packages/flutter_tools/test/commands.shard/hermetic/symbolize_test.dart‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,33 @@ void main() {
5353
);
5454
});
5555

56+
// Regression test for https://github.com/flutter/flutter/issues/191205.
57+
testUsingContext('DwarfSymbolizationService handles stream errors without crashing', () async {
58+
final symbolizationService = DwarfSymbolizationService(
59+
symbolsTransformer: (Uint8List symbols) {
60+
return StreamTransformer<String, String>.fromHandlers(
61+
handleData: (String data, EventSink<String> sink) {
62+
sink.addError('Test error');
63+
},
64+
);
65+
},
66+
);
67+
final output = StreamController<List<int>>();
68+
69+
final Future<void> decodeFuture = symbolizationService.decode(
70+
input: Stream<Uint8List>.fromIterable(<Uint8List>[
71+
const Utf8Encoder().convert('Hello, World\n'),
72+
]),
73+
symbols: Uint8List(0),
74+
output: IOSink(output.sink),
75+
);
76+
77+
expect(
78+
decodeFuture,
79+
throwsA(isA<ToolExit>().having((ToolExit e) => e.message, 'message', contains('Test error'))),
80+
);
81+
});
82+
5683
testUsingContext(
5784
'symbolize exits when --debug-info and --unit-id-debug-info arguments are missing',
5885
() async {

0 commit comments

Comments
 (0)