You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Select Device" doesn't work if the daemon has terminated, but provides no feedback #4510
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
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.
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)
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).
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...
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.
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
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.
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
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?
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?
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?).
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.
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.
The problem is that dart:io does not give us any futher information.
It looks like the error is reported here:
} onProcessExceptioncatch (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?).
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.
@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.
@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!
Activity
DanTup commentedon Apr 26, 2023
Can you try enabling the daemon log in your VS Code user settings and getting a copy next time you see this?
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.
guidezpl commentedon Apr 28, 2023
No toast, but I just tried to select a device 5 times, and it's not working.
DanTup commentedon Apr 28, 2023
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:
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)
christopherfujino commentedon Apr 28, 2023
So this error message means that running
adb devices -lthrew 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).christopherfujino commentedon Apr 28, 2023
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...DanTup commentedon Apr 28, 2023
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.
[-]Sometimes cannot select device[/-][+]"Select Device" doesn't work if the daemon has terminated, but provides no feedback[/+]christopherfujino commentedon Apr 28, 2023
Do you mean the Flutter daemon, or the adb one?
DanTup commentedon Apr 28, 2023
The flutter one started by VS Code with
flutter daemon. Both that issue and this are caused by theflutter daemonprocess terminating.In the log above, the second line about the process terminating refers to the
flutter daemonprocess that VS Code spawned and keeps for the session (to be notified of devices connecting/disconnected, and handling a few requests such asgetSupportedPlatforms):christopherfujino commentedon Apr 28, 2023
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?
christopherfujino commentedon Apr 28, 2023
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?
DanTup commentedon Apr 28, 2023
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?).christopherfujino commentedon Apr 28, 2023
The problem is that dart:io does not give us any futher information.
guidezpl commentedon Apr 29, 2023
Indeed, just happened again, and the Flutter daemon crash was collapsed in the notification bell. The relevant logs are
which is strange because both
/opt/homebrew/bin/adb(in shell, returned bywhich adb) and/Users/plg/Library/Android/sdk/platform-tools/adbexist and run fine.DanTup commentedon Apr 30, 2023
@christopherfujino
It looks like the error is reported here:
But this is only including
executable. The exception has amessageandexitCodethat 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 callingadbat this point.. does it do some polling?).DanTup commentedon May 2, 2023
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.
christopherfujino commentedon May 2, 2023
Sure!
DanTup commentedon May 3, 2023
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!
guidezpl commentedon May 3, 2023
Will do, thanks!
Re-show Flutter daemon terminated message when trying to call API