Repository: flutter
Issue: Error "The Flutter Daemon has terminated" after waking PC from sleep mode
Labels: c: crash,platform-android,tool,platform-windows,P2,team-android,triaged-android

I see error dialogs "The Flutter Daemon has terminated." and "Cannot call write after a stream was destroyed."  every time I wake up my PC from sleep mode and try to start a new debug session. 

Steps to reproduce:
1. Connect a device to USB cable for debugging
2. Open your Flutter project in VS Code
3. Start a debug session, works normally
4. Stop the debug session
5. Put your PC to sleep
6. Wake up your PC
7. Try starting a new debug session
8. The error dialogs are shown and debugging is not started
9. Click "Cancel" button in the "Cannot call write after a stream was destroyed." dialog and the "Restart" button in the "The Flutter Daemon has terminated." dialog.
10. Start a debug session, now it works again.

Log created with these steps:
- Run flutter daemon -v from a terminal
- Paste in [{"id":"2","method":"device.enable"}] and press enter
- Wait for your device to show up in the JSON output
- Put your PC to sleep
- Wake your PC

```
.
.
.
[   +6 ms] Starting device daemon...
[{"event":"daemon.connected","params":{"version":"0.5.3","pid":23088}}]
[{"id":"2","method":"device.enable"}]
[{"id":"2","result":[null,null,null]}]
[+12447 ms] executing: c:\tools\android-sdk\platform-tools\adb.exe devices -l
[  +84 ms] List of devices attached
           ad0c16039914a951e1     device product:heroltexx model:SM_G930F device:herolte transport_id:12
[{"event":"device.added","params":{"id":"ad0c16039914a951e1","name":"SM G930F","platform":"android-arm64","emulator":false,"category":"mobile","platformType":"android","ephemeral":true,"emulatorId":null}}]
[+4008 ms] executing: c:\tools\android-sdk\platform-tools\adb.exe devices -l
[  +87 ms] List of devices attached
           ad0c16039914a951e1     device product:heroltexx model:SM_G930F device:herolte transport_id:12
[+4003 ms] executing: c:\tools\android-sdk\platform-tools\adb.exe devices -l
[  +76 ms] List of devices attached
           ad0c16039914a951e1     device product:heroltexx model:SM_G930F device:herolte transport_id:12
[+4003 ms] executing: c:\tools\android-sdk\platform-tools\adb.exe devices -l
[  +81 ms] List of devices attached
           ad0c16039914a951e1     device product:heroltexx model:SM_G930F device:herolte transport_id:12
[+4004 ms] executing: c:\tools\android-sdk\platform-tools\adb.exe devices -l
[  +73 ms] List of devices attached
           ad0c16039914a951e1     device product:heroltexx model:SM_G930F device:herolte transport_id:12
[+4002 ms] executing: c:\tools\android-sdk\platform-tools\adb.exe devices -l
[+25213 ms] adb.exe F 07-28 13:23:35  1384  6580 fdevent_poll.cpp:64] failed to create fdevent interrupt socketpair: Invalid argument
Unable to run "adb", check your Android SDK installation and ANDROID_HOME environment variable: c:\tools\android-sdk\platform-tools\adb.exe

#0      throwToolExit (package:flutter_tools/src/base/common.dart:14:3)
#1      AndroidDevices.pollingGetDevices (package:flutter_tools/src/android/android_device_discovery.dart:62:7)
<asynchronous suspension>
#2      PollingDeviceDiscovery._initTimer.<anonymous closure> (package:flutter_tools/src/device.dart:300:44)
#3      _rootRun (dart:async/zone.dart:1180:38)
#4      _CustomZone.run (dart:async/zone.dart:1077:19)
#5      _CustomZone.runGuarded (dart:async/zone.dart:979:7)
#6      _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
#7      _rootRun (dart:async/zone.dart:1184:13)
#8      _CustomZone.run (dart:async/zone.dart:1077:19)
#9      _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1003:23)
#10     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:23:15)
#11     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
#12     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
#13     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
```

[√] Flutter (Channel stable, v1.17.5, on Microsoft Windows [Version 10.0.18363.959], locale en-US)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.5)
[√] VS Code (version 1.47.3)
[√] Connected device (1 available)

• No issues found!