Repository navigation
Crash: "Bad state: Future already completed" when hot restarting #74407
Copy link
Copy link
Closed
Labels
a: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our teststoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Milestone
Description
Using current master version (5b0f69f), I reliably see a crash when trying to hot reload (on iOS Simulator). I can reproduce from the terminal and using a clean flutter create project.
- Run
flutter create foo && cd foo - Run
flutter run(I'm using iOS Simulator, I'm unsure if that matters) - When the app loads, press
Shift+Rto hot restart - If it doesn't crash, press
Shift+Ragain
It always seems to happen within 1 or 2 restarts for me.
command
flutter run --target lib/main.dart -d F3122E57-B9F0-4AAB-9C88-92EBE7B77289
exception
StateError: Bad state: Future already completed
#0 _AsyncCompleter.complete (dart:async/future_impl.dart:45:31)
#1 ResidentRunner.waitForExtension.<anonymous closure> (package:flutter_tools/src/resident_runner.dart:1425:19)
#2 _rootRunUnary (dart:async/zone.dart:1362:47)
#3 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
#4 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
#5 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
#6 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
#7 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
#8 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7)
#9 _rootRun (dart:async/zone.dart:1346:47)
#10 _CustomZone.run (dart:async/zone.dart:1258:19)
#11 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#12 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#13 _rootRun (dart:async/zone.dart:1354:13)
#14 _CustomZone.run (dart:async/zone.dart:1258:19)
#15 _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
#16 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
#17 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#18 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
#19 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:120:13)
#20 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:185:5)
flutter doctor
[✓] Flutter (Channel master, 1.26.0-2.0.pre.451, on macOS 11.1 20C69 darwin-x64, locale en-GB)
• Flutter version 1.26.0-2.0.pre.451 at /Users/danny/Dev/Google/flutter
• Framework revision 5b0f69f961 (2 hours ago), 2021-01-21 07:49:03 -0500
• Engine revision 30bb7452f8
• Dart version 2.12.0 (build 2.12.0-247.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/danny/Library/Android/sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.3, Build version 12C33
• CocoaPods version 1.10.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
[✓] Connected device (3 available)
• iPhone 12 Pro Max (mobile) • F3122E57-B9F0-4AAB-9C88-92EBE7B77289 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
• macOS (desktop) • macos • darwin-x64 • macOS 11.1 20C69 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.141
• No issues found!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a: tests"flutter test", flutter_test, or one of our tests"flutter test", flutter_test, or one of our teststoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Activity
DanTup commentedon Jan 21, 2021
@kenzieschmoll I think this may be related to #74251 - this handler may be firing again after a hot restarts?
flutter/packages/flutter_tools/lib/src/resident_runner.dart
Lines 1423 to 1427 in b45088c
jonahwilliams commentedon Jan 21, 2021
Right, and we will also need to reset the devtools url on hot restart
kenzieschmoll commentedon Jan 21, 2021
@jonahwilliams why is that?
kenzieschmoll commentedon Jan 21, 2021
Update - have a fix - working on writing a test.
jonahwilliams commentedon Jan 21, 2021
On a hot restart we're going to kill and recreate the main isolate, so the previously set devtools URL field will be empty. This should be easy to confirm by adding a new case to the existing integration test
kenzieschmoll commentedon Jan 21, 2021
Re-opening because we need to add a test for this.
jonahwilliams commentedon Jan 21, 2021
So we do have a test for this crash, it just wasn't running. We do need a test for the hot restart case but that is a much lower severity.
jonahwilliams commentedon Jan 21, 2021
Closing in favor of #74442
Hixie commentedon Jan 21, 2021
Landing the PR to fix this P0 without a test was done on the understanding that enabling tests for it would be considered a P0-level task.
jonahwilliams commentedon Jan 23, 2021
From offline discussion (Well, online actually) - there was a test that the PR failed, but due to a separate infra issue that test was not running. The fix has landed, and the tests have been restored.
github-actions commentedon Aug 6, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.