Repository: flutter
Issue: Flutter upgrade failed with unhandled "Future already completed" exceptions
Labels: tool,dependency: dart,P2,team-tool,triaged-tool

## Steps to Reproduce

1. ... Download latest flutter macOS version; Put flutter folder into ```/Applications/```; Add ```flutter/bin``` to ```$PATH```
2. ... Run ```flutter precache``` and it finishes successfully.
3. ... Run ```flutter upgrade```

## Logs

```
$ flutter upgrade
Upgrading Flutter from /Applications/Android/flutter...
From https://github.com/flutter/flutter
 + 20e59316b...2d2a1ffec stable                  -> origin/stable  (forced update)
 * [new branch]          Hixie-patch-1           -> origin/Hixie-patch-1
 + 20e59316b...2d2a1ffec beta                    -> origin/beta  (forced update)
   0a39d8d92..f5733f7a6  dev                     -> origin/dev
 * [new branch]          generated_explicit_type -> origin/generated_explicit_type
 * [new branch]          keyonghan-deviceLabReadme -> origin/keyonghan-deviceLabReadme
   aa6384cba..0ef89bb96  master                  -> origin/master
 * [new branch]          potato620-patch-1       -> origin/potato620-patch-1
 * [new branch]          refactor                -> origin/refactor
 * [new branch]          revert-37962-show-search-app-bar-theme -> origin/revert-37962-show-search-app-bar-theme
 * [new branch]          revert-38861-use_frame_timings -> origin/revert-38861-use_frame_timings
 * [new branch]          revert-38922-text-docs  -> origin/revert-38922-text-docs
 * [new branch]          v1.9.1-hotfixes         -> origin/v1.9.1-hotfixes
 * [new tag]             v1.10.2                 -> v1.10.2
 * [new tag]             v1.8.3                  -> v1.8.3
 * [new tag]             v1.8.4                  -> v1.8.4
 * [new tag]             v1.9.0                  -> v1.9.0
 * [new tag]             v1.9.1                  -> v1.9.1
 * [new tag]             v1.9.1+hotfix.1         -> v1.9.1+hotfix.1
 * [new tag]             v1.9.1+hotfix.2         -> v1.9.1+hotfix.2
 * [new tag]             v1.10.0                 -> v1.10.0
 * [new tag]             v1.10.1                 -> v1.10.1
 * [new tag]             v1.9.2                  -> v1.9.2
 * [new tag]             v1.9.3                  -> v1.9.3
 * [new tag]             v1.9.4                  -> v1.9.4
 * [new tag]             v1.9.5                  -> v1.9.5
 * [new tag]             v1.9.6                  -> v1.9.6
 * [new tag]             v1.9.7                  -> v1.9.7
Updating d51fd86cd..2d2a1ffec
 PATENTS => PATENT_GRANT                            |     0
 dev/automated_tests/icon/test.png                  |   Bin 0 -> 423 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 11112 -> 10932 bytes
 dev/devicelab/images/agent-statuses.png            |   Bin 18399 -> 13842 bytes
 dev/devicelab/images/broken-test.png               |   Bin 69897 -> 56878 bytes
 dev/devicelab/images/legend.png                    |   Bin 48845 -> 30220 bytes
 .../drawable-land-xxhdpi/flutter_splash_screen.png |   Bin 0 -> 3861 bytes
 .../res/drawable-xxhdpi/flutter_splash_screen.png  |   Bin 0 -> 4428 bytes
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |   Bin 0 -> 544 bytes
 .../mipmap-land-xxhdpi/flutter_splash_screen.png   |   Bin 0 -> 3861 bytes
 .../app/src/main/res/mipmap-mdpi/ic_launcher.png   |   Bin 0 -> 442 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |   Bin 0 -> 721 bytes
 .../res/mipmap-xxhdpi/flutter_splash_screen.png    |   Bin 0 -> 4428 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |   Bin 0 -> 1031 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |   Bin 0 -> 1443 bytes
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |   Bin 0 -> 544 bytes
 .../app/src/main/res/mipmap-mdpi/ic_launcher.png   |   Bin 0 -> 442 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |   Bin 0 -> 721 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |   Bin 0 -> 1031 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |   Bin 0 -> 1443 bytes
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |   Bin 0 -> 544 bytes
 .../app/src/main/res/mipmap-mdpi/ic_launcher.png   |   Bin 0 -> 442 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |   Bin 0 -> 721 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |   Bin 0 -> 1031 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |   Bin 0 -> 1443 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 0 -> 10932 bytes
 .../AppIcon.appiconset/Icon-App-20x20@1x.png       |   Bin 0 -> 564 bytes
 .../AppIcon.appiconset/Icon-App-20x20@2x.png       |   Bin 0 -> 1283 bytes
 .../AppIcon.appiconset/Icon-App-20x20@3x.png       |   Bin 0 -> 1588 bytes
 .../AppIcon.appiconset/Icon-App-29x29@1x.png       |   Bin 0 -> 1025 bytes
 .../AppIcon.appiconset/Icon-App-29x29@2x.png       |   Bin 0 -> 1716 bytes
 .../AppIcon.appiconset/Icon-App-29x29@3x.png       |   Bin 0 -> 1920 bytes
 .../AppIcon.appiconset/Icon-App-40x40@1x.png       |   Bin 0 -> 1283 bytes
 .../AppIcon.appiconset/Icon-App-40x40@2x.png       |   Bin 0 -> 1895 bytes
 .../AppIcon.appiconset/Icon-App-40x40@3x.png       |   Bin 0 -> 2665 bytes
 .../AppIcon.appiconset/Icon-App-60x60@2x.png       |   Bin 0 -> 2665 bytes
 .../AppIcon.appiconset/Icon-App-60x60@3x.png       |   Bin 0 -> 3831 bytes
 .../AppIcon.appiconset/Icon-App-76x76@1x.png       |   Bin 0 -> 1888 bytes
 .../AppIcon.appiconset/Icon-App-76x76@2x.png       |   Bin 0 -> 3294 bytes
 .../AppIcon.appiconset/Icon-App-83.5x83.5@2x.png   |   Bin 0 -> 3612 bytes
 .../LaunchImage.imageset/LaunchImage.png           |   Bin 0 -> 68 bytes
 .../LaunchImage.imageset/LaunchImage@2x.png        |   Bin 0 -> 68 bytes
 .../LaunchImage.imageset/LaunchImage@3x.png        |   Bin 0 -> 68 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 11112 -> 10932 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 11112 -> 10932 bytes
 .../ios_host_app/Flutter/.gitkeep                  |     0
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 11112 -> 10932 bytes
 dev/snippets/assets/code_sample.png                |   Bin 58572 -> 39037 bytes
 dev/snippets/assets/code_snippet.png               |   Bin 202228 -> 113476 bytes
 .../app/src/main/res/mipmap-hdpi/ic_background.png |   Bin 18209 -> 2583 bytes
 .../app/src/main/res/mipmap-hdpi/ic_foreground.png |   Bin 3581 -> 2063 bytes
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |   Bin 3951 -> 3116 bytes
 .../src/main/res/mipmap-xhdpi/ic_background.png    |   Bin 31807 -> 3231 bytes
 .../src/main/res/mipmap-xhdpi/ic_foreground.png    |   Bin 5455 -> 2721 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |   Bin 5326 -> 3980 bytes
 .../src/main/res/mipmap-xxhdpi/ic_background.png   |   Bin 72301 -> 4963 bytes
 .../src/main/res/mipmap-xxhdpi/ic_foreground.png   |   Bin 10303 -> 4613 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |   Bin 9650 -> 7167 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_background.png  |   Bin 125855 -> 6802 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_foreground.png  |   Bin 16499 -> 6155 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |   Bin 13901 -> 9897 bytes
 .../AppIcon.appiconset/Icon-120.png                |   Bin 1787 -> 1750 bytes
 .../AppIcon.appiconset/Icon-152.png                |   Bin 2162 -> 2003 bytes
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |   Bin 0 -> 544 bytes
 .../app/src/main/res/mipmap-mdpi/ic_launcher.png   |   Bin 0 -> 442 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |   Bin 0 -> 721 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |   Bin 0 -> 1031 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |   Bin 0 -> 1443 bytes
 examples/image_list/images/coast.jpg               |   Bin 0 -> 202344 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 0 -> 11112 bytes
 .../AppIcon.appiconset/Icon-App-20x20@1x.png       |   Bin 0 -> 564 bytes
 .../AppIcon.appiconset/Icon-App-20x20@2x.png       |   Bin 0 -> 1283 bytes
 .../AppIcon.appiconset/Icon-App-20x20@3x.png       |   Bin 0 -> 1588 bytes
 .../AppIcon.appiconset/Icon-App-29x29@1x.png       |   Bin 0 -> 1025 bytes
 .../AppIcon.appiconset/Icon-App-29x29@2x.png       |   Bin 0 -> 1716 bytes
 .../AppIcon.appiconset/Icon-App-29x29@3x.png       |   Bin 0 -> 1920 bytes
 .../AppIcon.appiconset/Icon-App-40x40@1x.png       |   Bin 0 -> 1283 bytes
 .../AppIcon.appiconset/Icon-App-40x40@2x.png       |   Bin 0 -> 1895 bytes
 .../AppIcon.appiconset/Icon-App-40x40@3x.png       |   Bin 0 -> 2665 bytes
 .../AppIcon.appiconset/Icon-App-60x60@2x.png       |   Bin 0 -> 2665 bytes
 .../AppIcon.appiconset/Icon-App-60x60@3x.png       |   Bin 0 -> 3831 bytes
 .../AppIcon.appiconset/Icon-App-76x76@1x.png       |   Bin 0 -> 1888 bytes
 .../AppIcon.appiconset/Icon-App-76x76@2x.png       |   Bin 0 -> 3294 bytes
 .../AppIcon.appiconset/Icon-App-83.5x83.5@2x.png   |   Bin 0 -> 3612 bytes
 .../LaunchImage.imageset/LaunchImage.png           |   Bin 0 -> 68 bytes
 .../LaunchImage.imageset/LaunchImage@2x.png        |   Bin 0 -> 68 bytes
 .../LaunchImage.imageset/LaunchImage@3x.png        |   Bin 0 -> 68 bytes
 .../app/src/main/res/mipmap-hdpi/ic_launcher.png   |   Bin 3481 -> 3041 bytes
 .../app/src/main/res/mipmap-mdpi/ic_launcher.png   |   Bin 2121 -> 1958 bytes
 .../app/src/main/res/mipmap-xhdpi/ic_launcher.png  |   Bin 5061 -> 4372 bytes
 .../app/src/main/res/mipmap-xxhdpi/ic_launcher.png |   Bin 8878 -> 7152 bytes
 .../src/main/res/mipmap-xxxhdpi/ic_launcher.png    |   Bin 13629 -> 10393 bytes
 .../AppIcon.appiconset/Icon-60@2x.png              |   Bin 7210 -> 5633 bytes
 .../AppIcon.appiconset/Icon-60@3x.png              |   Bin 12818 -> 9562 bytes
 .../Assets.xcassets/AppIcon.appiconset/Icon-76.png |   Bin 3804 -> 3115 bytes
 .../AppIcon.appiconset/Icon-76@2x.png              |   Bin 10082 -> 7587 bytes
 .../AppIcon.appiconset/Icon-83.5@2x.png            |   Bin 11552 -> 8627 bytes
 .../AppIcon.appiconset/Icon-Notification@2x.png    |   Bin 1529 -> 1404 bytes
 .../AppIcon.appiconset/Icon-Notification@3x.png    |   Bin 2663 -> 2297 bytes
 .../AppIcon.appiconset/Icon-Small-40.png           |   Bin 1529 -> 1404 bytes
 .../AppIcon.appiconset/Icon-Small-40@2x.png        |   Bin 4058 -> 3282 bytes
 .../AppIcon.appiconset/Icon-Small-40@3x.png        |   Bin 7210 -> 5633 bytes
 .../AppIcon.appiconset/Icon-Small@2x.png           |   Bin 2518 -> 2164 bytes
 .../AppIcon.appiconset/Icon-Small@3x.png           |   Bin 4520 -> 3725 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 11112 -> 10932 bytes
 .../AppIcon.appiconset/Icon-App-1024x1024@1x.png   |   Bin 11112 -> 10932 bytes
 .../test_data/basic_project.dart                   |     0
 .../test_data/hot_reload_project.dart              |     0
 .../test_data/project.dart                         |     0
 .../test_data/stepping_project.dart                |     0
 .../test_data/tests_project.dart                   |     0
 1259 files changed, 84888 insertions(+), 19872 deletions(-)

Upgrading engine...
Downloading Dart SDK from Flutter engine b863200c37df4ed378042de11c4e9ff34e4e58c9...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0  263M    0  3492    0     0   7449      0 10:19:07 --:--:-- 10:19:07  7445
  3  263M    3 9854k    0     0  7488k      0  0:00:36  0:00:01  0:00:35 7488k
 15  263M   15 40.5M    0     0  17.4M      0  0:00:15  0:00:02  0:00:13 17.4M
 27  263M   27 71.9M    0     0  21.7M      0  0:00:12  0:00:03  0:00:09 21.6M
 42  263M   42  112M    0     0  26.1M      0  0:00:10  0:00:04  0:00:06 26.1M
 52  263M   52  137M    0     0  25.9M      0  0:00:10  0:00:05  0:00:05 28.4M
 62  263M   62  163M    0     0  25.7M      0  0:00:10  0:00:06  0:00:04 30.5M
 71  263M   71  188M    0     0  25.8M      0  0:00:10  0:00:07  0:00:03 29.6M
 80  263M   80  212M    0     0  25.4M      0  0:00:10  0:00:08  0:00:02 28.0M
 90  263M   90  237M    0     0  25.5M      0  0:00:10  0:00:09  0:00:01 24.9M
 96  263M   96  255M    0     0  24.7M      0  0:00:10  0:00:10 --:--:-- 23.5M
100  263M  100  263M    0     0  25.0M      0  0:00:10  0:00:10 --:--:-- 23.9M
Building flutter tool...
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (8 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (7 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (6 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (5 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (4 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _Completer.completeError (dart:async/future_impl.dart:21:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext (dart:io-patch/socket_patch.dart:459:23)
#2      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:537:48)
#3      _NativeSocket.reportError (dart:io-patch/socket_patch.dart:1101:32)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:939:13)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (3 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _Completer.completeError (dart:async/future_impl.dart:21:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext (dart:io-patch/socket_patch.dart:459:23)
#2      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:537:48)
#3      _NativeSocket.reportError (dart:io-patch/socket_patch.dart:1101:32)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:939:13)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (2 tries left)
Unhandled exception:
Bad state: Future already completed
#0      _Completer.completeError (dart:async/future_impl.dart:21:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext (dart:io-patch/socket_patch.dart:459:23)
#2      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:537:48)
#3      _NativeSocket.reportError (dart:io-patch/socket_patch.dart:1101:32)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:939:13)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (1 tries left)
Command 'pub upgrade' still failed after 10 tries, giving up.
```

```
$ flutter doctor -v
Building flutter tool...
Unhandled exception:
Bad state: Future already completed
#0      _AsyncCompleter.complete (dart:async/future_impl.dart:39:31)
#1      _NativeSocket.startConnect.<anonymous closure>.connectNext.<anonymous closure> (dart:io-patch/socket_patch.dart:523:23)
#2      _NativeSocket.issueWriteEvent.issue (dart:io-patch/socket_patch.dart:878:14)
#3      _NativeSocket.issueWriteEvent (dart:io-patch/socket_patch.dart:885:12)
#4      _NativeSocket.multiplex (dart:io-patch/socket_patch.dart:906:11)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds... (9 tries left)
```