Skip to content

Crash: "Bad state: Future already completed" when hot restarting #74407

Closed

Description

@DanTup

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+R to hot restart
  • If it doesn't crash, press Shift+R again

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!

Activity

  1. DanTup commented on Jan 21, 2021

    @DanTup
    ContributorAuthor

    @kenzieschmoll I think this may be related to #74251 - this handler may be firing again after a hot restarts?

    vmService.onExtensionEvent.listen((vm_service.Event event) {
    if (event.json['extensionKind'] == 'Flutter.FrameworkInitialization') {
    completer.complete();
    }
    });

  2. jonahwilliams commented on Jan 21, 2021

    @jonahwilliams
    Contributor

    Right, and we will also need to reset the devtools url on hot restart

  3. kenzieschmoll commented on Jan 21, 2021

    @kenzieschmoll
    Member

    Right, and we will also need to reset the devtools url on hot restart

    @jonahwilliams why is that?

  4. kenzieschmoll commented on Jan 21, 2021

    @kenzieschmoll
    Member

    Update - have a fix - working on writing a test.

  5. jonahwilliams commented on Jan 21, 2021

    @jonahwilliams
    Contributor

    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

  6. added
    P0Critical issues such as a build break or regression
    c: crashStack traces logged to the console
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jan 21, 2021
  7. kenzieschmoll commented on Jan 21, 2021

    @kenzieschmoll
    Member

    Re-opening because we need to add a test for this.

  8. jonahwilliams commented on Jan 21, 2021

    @jonahwilliams
    Contributor

    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.

  9. added
    a: tests"flutter test", flutter_test, or one of our tests
    and removed
    P0Critical issues such as a build break or regression
    c: crashStack traces logged to the console
    on Jan 21, 2021
  10. jonahwilliams commented on Jan 21, 2021

    @jonahwilliams
    Contributor

    Closing in favor of #74442

  11. Hixie commented on Jan 21, 2021

    @Hixie
    Contributor

    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.

  12. jonahwilliams commented on Jan 23, 2021

    @jonahwilliams
    Contributor

    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.

  13. github-actions commented on Aug 6, 2021

    @github-actions

    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 -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: tests"flutter test", flutter_test, or one of our teststoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions