Skip to content

"Select Device" doesn't work if the daemon has terminated, but provides no feedback #4510

Closed

Description

@guidezpl

Describe the bug
After a bit of usage, tapping the device selector in the bottom right results in no action. The "Flutter: Select device" command also does nothing. Only restarting VS Code fixes the issue, temporarily.

To Reproduce
Unclear for now

Please complete the following information:

  • Operating System and version: macOS Ventura
  • VS Code version: 1.77.3
  • Dart extension version: 3.62
  • Dart/Flutter SDK version: 3.10.0-10.0.pre.17

Logs

Wed Apr 26 2023 [10:46:07 GMT+0200 (Central European Summer Time)] Log file started
[10:46:10 AM] [General] [Info] Returning cached promise for getSupportedPlatforms()
Wed Apr 26 2023 [10:46:12 GMT+0200 (Central European Summer Time)] Log file ended

Activity

  1. DanTup commented on Apr 26, 2023

    @DanTup
    Member

    Can you try enabling the daemon log in your VS Code user settings and getting a copy next time you see this?

    // relative paths will be relative to the open workspace, but absolute paths work (though multiple open VS Code instances may overwrite each others)
    "dart.flutterDaemonLogFile": "logs/flutter_daemon.txt",
    

    I wonder if maybe the daemon is crashing? This came up in #4475 but I don't know what would cause it. If it's common for the daemon to crash we should probably restart is silently and file a flutter/flutter bug.

    If this was happening, you should see a toast notification saying it had terminated though.

  2. added
    awaiting infoRequires more information from the customer to progress
    on Apr 26, 2023
  3. guidezpl commented on Apr 28, 2023

    @guidezpl
    ContributorAuthor
    !! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!
    
    Dart Code extension: 3.62.0
    Flutter extension: 3.62.0 (activated)
    
    App: Visual Studio Code
    Version: 1.77.3
    Platform: mac
    
    HTTP_PROXY: undefined
    NO_PROXY: undefined
    
    Logging Categories:
        FlutterDaemon
    
    Fri Apr 28 2023 [02:20:08 GMT+0200 (Central European Summer Time)] Log file started
    [2:20:08 AM] [FlutterDaemon] [Info] Spawning /Users/plg/Developer/flutter-dev/bin/flutter with args ["daemon"]
    [2:20:08 AM] [FlutterDaemon] [Info] ..  in /Users/plg/Developer/flutter-dev
    [2:20:08 AM] [FlutterDaemon] [Info] ..  with {"toolEnv":{"FLUTTER_HOST":"VSCode","PUB_ENVIRONMENT":"vscode.dart-code"}}
    [2:20:08 AM] [FlutterDaemon] [Info]     PID: 58071
    [2:20:08 AM] [FlutterDaemon] [Info] ==> [{"id":"1","method":"emulator.getEmulators"}]
    [2:20:09 AM] [FlutterDaemon] [Info] <== [{"event":"daemon.connected","params":{"version":"0.6.1","pid":48785}}]
    [2:20:09 AM] [FlutterDaemon] [Info] ==> [{"id":"2","method":"device.enable"}]
    [2:20:09 AM] [FlutterDaemon] [Info] <== [{"event":"daemon.logMessage","params":{"level":"status","message":"Starting device daemon..."}}]
    [2:20:10 AM] [FlutterDaemon] [Info] <== [{"id":"2"}]
    [2:20:10 AM] [FlutterDaemon] [Info] <== [{"id":"1","result":[{"id":"apple_ios_simulator","name":"iOS Simulator","category":"mobile","platformType":"ios"},{"id":"Pixel_6_Pro_API_U","name":"Pixel 6 Pro API U","category":"mobile","platformType":"android"}]}]
    [2:20:14 AM] [FlutterDaemon] [Info] <== [{"event":"device.added","params":{"id":"macos","name":"macOS","platform":"darwin","emulator":false,"category":"desktop","platformType":"macos","ephemeral":false,"emulatorId":null,"sdk":"macOS 13.4 22F5037d darwin-arm64","capabilities":{"hotReload":true,"hotRestart":true,"screenshot":false,"fastStart":false,"flutterExit":true,"hardwareRendering":true,"startPaused":true}}}]
    [2:20:14 AM] [FlutterDaemon] [Info] ==> [{"id":"3","method":"daemon.getSupportedPlatforms","params":{"projectRoot":"/Users/plg/Developer/gallery"}}]
    [2:20:14 AM] [FlutterDaemon] [Info] <== [{"id":"3","result":{"platforms":["linux","macos","windows","ios","android","web"]}}]
    [2:20:15 AM] [FlutterDaemon] [Info] <== [{"event":"device.added","params":{"id":"chrome","name":"Chrome","platform":"web-javascript","emulator":false,"category":"web","platformType":"web","ephemeral":false,"emulatorId":null,"sdk":"Google Chrome 112.0.5615.137","capabilities":{"hotReload":true,"hotRestart":true,"screenshot":false,"fastStart":false,"flutterExit":false,"hardwareRendering":true,"startPaused":true}}}]
    [9:56:39 AM] [FlutterDaemon] [Info] <== [{"event":"daemon.logMessage","params":{"level":"error","message":"Unable to run \"adb\", check your Android SDK installation and ANDROID_SDK_ROOT environment variable: /Users/plg/Library/Android/sdk/platform-tools/adb"}}]
    [9:56:39 AM] [FlutterDaemon] [Info] Process /Users/plg/Developer/flutter-dev/bin/flutter terminated! 1, null
    [2:01:28 PM] [FlutterDaemon] [Info] ==> [{"id":"4","method":"daemon.getSupportedPlatforms","params":{"projectRoot":"/Users/plg/Developer/gallery"}}]
    [2:03:11 PM] [FlutterDaemon] [Info] ==> [{"id":"5","method":"daemon.getSupportedPlatforms","params":{"projectRoot":"/Users/plg/Developer/gallery"}}]
    
    

    No toast, but I just tried to select a device 5 times, and it's not working.

  4. DanTup commented on Apr 28, 2023

    @DanTup
    Member

    Seems like the daemon was working fine at 2:20am when it detected a device, and then at 9:56am it generated an error and terminated:

    [9:56:39 AM] [FlutterDaemon] [Info] <== [{"event":"daemon.logMessage","params":{"level":"error","message":"Unable to run \"adb\", check your Android SDK installation and ANDROID_SDK_ROOT environment variable: /Users/plg/Library/Android/sdk/platform-tools/adb"}}]
    [9:56:39 AM] [FlutterDaemon] [Info] Process /Users/plg/Developer/flutter-dev/bin/flutter terminated! 1, null
    

    Is it possible the toast is collapsed in your notification bell (bottom right status bar)? VS Code hides notifications about 10-15s, and there were many hours between it terminating and you then trying to select a device.

    It's not clear to me why this error occurred when it did though.. there's no traffic from VS Code to the daemon, so presumably something happened within the tool that triggered this. I think perhaps the error reported here ("Unable to run adb") should be expanded to help debug this - what happened that made flutter_tools decide it couldn't be run? Could it not find it? Did it exit with an error? Did it produce unexpected output?

    We could update Dart-Code to silently restart the daemon the first X times this happens, and only report if it's crashed more than X times (although doing this probably requires a bunch of refactoring, since our current restart is to restart the whole extension which is too disruptive to do automatically).

    It'd be nice to track down what's causing this though (FYI @christopherfujino)

  5. christopherfujino commented on Apr 28, 2023

    @christopherfujino

    So this error message means that running adb devices -l threw a ProcessException (this probably means it exited non-zero)

    https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/android/android_device_discovery.dart#L71

    In that toolExit however, we interpolate at the end the caught exception, the message of which appears to just be the path to the binary it tried (/Users/plg/Library/Android/sdk/platform-tools/adb)? I suspect the tool is somehow swallowing the real error message, I'll file a bug to give a more helpful message. (I'm assuming since a restart works, it's not that the binary isn't there).

  6. christopherfujino commented on Apr 28, 2023

    @christopherfujino

    Actually, it looks like this is what happens when the process manager can't find the binary on the search path. This is getting delegated right to io.Process.run() https://github.com/dart-lang/sdk/blob/main/sdk/lib/io/process.dart#L404. I'm not sure why it would sometimes not find the binary...

  7. DanTup commented on Apr 28, 2023

    @DanTup
    Member

    Yeah, that does sound odd. In #4475 both @kenzieschmoll and @polina-c noted that they see issues frequently which also appear to be the daemon terminating. I made some changes so that it doesn't block launching an app, but it doesn't address the real issue of the daemon being unresponsive. I don't know the cause is the same for all of them (or why we don't get more reports of this from external users).

    At a minimum, the VS Code extension should re-prompt about the daemon having terminated if someone tries to interact with it (eg. opening the device selector) after we know the process has terminated. The log file above suggests we just tried to send a message to it, despite the process being gone.

  8. removed
    awaiting infoRequires more information from the customer to progress
    on Apr 28, 2023
  9. added this to the v3.64.0 milestone on Apr 28, 2023
  10. added
    in flutterRelates to running Flutter apps
    in commandsRelates to commands (usually invoked from the command Palette)
    on Apr 28, 2023
  11. changed the title [-]Sometimes cannot select device[/-] [+]"Select Device" doesn't work if the daemon has terminated, but provides no feedback[/+] on Apr 28, 2023
  12. christopherfujino commented on Apr 28, 2023

    @christopherfujino

    Yeah, that does sound odd. In #4475 both @kenzieschmoll and @polina-c noted that they see issues frequently which also appear to be the daemon terminating. I made some changes so that it doesn't block launching an app, but it doesn't address the real issue of the daemon being unresponsive. I don't know the cause is the same for all of them (or why we don't get more reports of this from external users).

    At a minimum, the VS Code extension should re-prompt about the daemon having terminated if someone tries to interact with it (eg. opening the device selector) after we know the process has terminated. The log file above suggests we just tried to send a message to it, despite the process being gone.

    Do you mean the Flutter daemon, or the adb one?

  13. DanTup commented on Apr 28, 2023

    @DanTup
    Member

    Do you mean the Flutter daemon, or the adb one?

    The flutter one started by VS Code with flutter daemon. Both that issue and this are caused by the flutter daemon process terminating.

    In the log above, the second line about the process terminating refers to the flutter daemon process that VS Code spawned and keeps for the session (to be notified of devices connecting/disconnected, and handling a few requests such as getSupportedPlatforms):

    [9:56:39 AM] [FlutterDaemon] [Info] <== [{"event":"daemon.logMessage","params":{"level":"error","message":"Unable to run \"adb\", check your Android SDK installation and ANDROID_SDK_ROOT environment variable: /Users/plg/Library/Android/sdk/platform-tools/adb"}}]
    [9:56:39 AM] [FlutterDaemon] [Info] Process /Users/plg/Developer/flutter-dev/bin/flutter terminated! 1, null
    
  14. christopherfujino commented on Apr 28, 2023

    @christopherfujino

    Ahh right, I see what you mean. I was trying to figure out why the process failed and you were talking about what DartCode should do WHEN the daemon exits.

    Should the daemon send an event before tool exiting?

  15. christopherfujino commented on Apr 28, 2023

    @christopherfujino

    Well, I guess it did here (that message was from the ToolExit exception that was thrown, so something must have caught it), should we somehow mark that it's going to cause the daemon to crash?

  16. DanTup commented on Apr 28, 2023

    @DanTup
    Member

    Dart-Code doesn't need anything extra - I'll change it to handle the termination better (initially just re-showing the "The flutter daemon has terminated" prompt if anything tries to call its APIs, giving the user a button to restart it). It might be nice to support automatically restarting it, but that needs some refactoring (in Dart-Code) to support restarting its services without a whole extension restart.

    I think all that's required of Flutter is probably helping understand exactly what happened that caused this exit. If it couldn't find the binary, why not? (what happened at [9:56:39 AM]? a stack trace that led to that error perhaps would've been useful - I wonder whether Flutter reports that since it was a tool exit?).

  17. christopherfujino commented on Apr 28, 2023

    @christopherfujino

    I think all that's required of Flutter is probably helping understand exactly what happened that caused this exit. If it couldn't find the binary, why not? (what happened at [9:56:39 AM]? a stack trace that led to that error perhaps would've been useful - I wonder whether Flutter reports that since it was a tool exit?).

    The problem is that dart:io does not give us any futher information.

  18. guidezpl commented on Apr 29, 2023

    @guidezpl
    ContributorAuthor

    Indeed, just happened again, and the Flutter daemon crash was collapsed in the notification bell. The relevant logs are

    [9:46:07 PM] [FlutterDaemon] [Info] <== [{"event":"daemon.logMessage","params":{"level":"error","message":"Unable to run \"adb\", check your Android SDK installation and ANDROID_SDK_ROOT environment variable: /Users/plg/Library/Android/sdk/platform-tools/adb"}}]
    [9:46:07 PM] [FlutterDaemon] [Info] Process /Users/plg/Developer/flutter-dev/bin/flutter terminated! 1, null
    [7:02:09 AM] [FlutterDaemon] [Info] ==> [{"id":"6","method":"daemon.getSupportedPlatforms","params":{"projectRoot":"/Users/plg/Developer/gallery"}}]
    

    which is strange because both /opt/homebrew/bin/adb (in shell, returned by which adb) and /Users/plg/Library/Android/sdk/platform-tools/adb exist and run fine.

  19. DanTup commented on Apr 30, 2023

    @DanTup
    Member

    @christopherfujino

    The problem is that dart:io does not give us any futher information.

    It looks like the error is reported here:

    } on ProcessException catch (exception) {
          throwToolExit(
            'Unable to run "adb", check your Android SDK installation and '
            '$kAndroidSdkRoot environment variable: ${exception.executable}',
          );

    But this is only including executable. The exception has a message and exitCode that might be useful to understand what failed? (I also wonder if the stacktrace may be useful, because it's not clear why Flutter was even calling adb at this point.. does it do some polling?).

  20. DanTup commented on May 2, 2023

    @DanTup
    Member

    I've pushed a fix that will re-show the "Flutter daemon has terminated" prompt (although saying "is not running" in this condition) if something tries to call its API after it has already exited.

    Because I don't know how common this is and the API is called on every debug session launch, I have throttled it to only show once per 10 minutes (so if you run the command, ignore the prompt, then run it again, you won't see the prompt a second time unless it's been 10 minutes). We can remove this in future if we're sure this isn't a widespread issue (although if it is, we need to find a better fix).

    @christopherfujino should I open a flutter/flutter issue about trying to capture some more context in the error (see my comment above - #4510 (comment)) to help track down what's happening here? @guidezpl is the third person (coincidentally all Googlers) to have reported this kind of issue.

  21. christopherfujino commented on May 2, 2023

    @christopherfujino

    @christopherfujino should I open a flutter/flutter issue about trying to capture some more context in the error (see my comment above - #4510 (comment)) to help track down what's happening here? @guidezpl is the third person (coincidentally all Googlers) to have reported this kind of issue.

    Sure!

  22. DanTup commented on May 3, 2023

    @DanTup
    Member

    I've opened flutter/flutter#125971 with some notes.

    @guidezpl the change I noticed above (re-showing the prompt up to once every 10 mins) is in the published Pre-release version, so if you're on that please let me know if you're not seeing it (or have any issues/feedback). Thanks!

  23. guidezpl commented on May 3, 2023

    @guidezpl
    ContributorAuthor

    Will do, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in commandsRelates to commands (usually invoked from the command Palette)in flutterRelates to running Flutter appsis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions