Repository navigation
Closed as not planned
Labels
P2Important issues not at the top of the work listteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team
Description
If I yank the cable from my device during installation (I know this isn't normal, but I'm simulating Dart-Code/Dart-Code#329!) then flutter run sends an app.stop notification but does not terminate; leaving the process around.
Since this is not daemon and starts the app immediately at startup, I would expect that on app start it would terminate (and if I send a stop command, I believe it does).
PS M:\Coding\Applications\flutter\examples\stocks> flutter run --machine
[{"event":"app.start","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","deviceId":"ZY2224ZKJJ","directory":"M:\\Coding\\Applications\\flutter\\examples\\stocks","supportsRestart":true}}]
Launching lib/main.dart on XT1562 in debug mode...
[{"event":"app.progress","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","id":"0","progressId":null,"message":"Initializing Gradle..."}}]
[{"event":"app.progress","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","id":"0","progressId":null,"finished":true}}]
[{"event":"app.progress","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","id":"1","progressId":null,"message":"Resolving dependencies..."}}]
// Cable yanked around here
[{"event":"app.progress","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","id":"1","progressId":null,"finished":true}}]
[{"event":"app.progress","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","id":"2","progressId":null,"message":"Running 'gradlew assembleDebug'..."}}]
[{"event":"app.progress","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","id":"2","progressId":null,"finished":true}}]
Built build\app/outputs/apk/app-debug.apk (21.6MB).
// Error comes back with a stop notification
error: device 'ZY2224ZKJJ' not found
[{"event":"app.stop","params":{"appId":"006f6f46-ba1e-4a68-aaf4-f3d53e9b8b80","error":"Exit code 1 from: M:\\Apps\\Android\\platform-tools\\adb -s ZY2224ZKJJ shell pm list packages io.flutter.examples.stocks"}}]
// Process is still alive
Is my understanding correct - flutter should terminate here?
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team
Activity
Hixie commentedon May 1, 2018
@DanTup What's the status of this one, do you know?
DanTup commentedon May 2, 2018
Honestly, I had forgotten about this since I raised it (it was raised well before I did any work on Flutter tools). However, I wonder if it's a similar issue to #16183 which I'm hoping to look at very soon.
DanTup commentedon Jun 21, 2018
This is still a problem. In some cases it doesn't even send a
stopnotification. I don't think the case linked above will help, since it's not clear if/when we should terminate the process.However I don't think it's isolated to --machine.. I left this for many minutes:
[-]`flutter run --machine` does not terminate after failure to install[/-][+]`flutter run` does not terminate after failure to install[/+]DanTup commentedon Jun 21, 2018
@devoncarew The errors above come seem to come from
AppDomainindaemon.dart, where we have this inhandleCommand:https://github.com/flutter/flutter/blob/a18f5e84a1045551774a6c12fd40fa4997356931/packages/flutter_tools/lib/src/commands/daemon.dart#L193L195
This is catching errors and sending them back the the client, but not terminating. Does it makes sense to terminate here? Maybe in the
flutter daemonwe shouldn't, but forflutter runit seems like an error should probably be fatal?Edit: This might be wrong; we think the error is being written directly to the output stream, not handled by the above..
DanTup commentedon Jun 27, 2018
@devoncarew Ok, I think I finally got to the bottom of why this is happening..
adboutputs message that look exactly like the ones influtter_tools(device 'x' not found.); these messages are coming from there. We have many places that calladband print its stdout/stderr.In the case I was testing, this is occurring in this code:
flutter/packages/flutter_tools/lib/src/android/android_device.dart
Lines 386 to 387 in 0fb2097
It looks like as part of the build we try to stop the app (presumably in case it's already running). However, this line does not inspect the return value of
stopApp(which isfalsein the case of an error) and just continues. If adb fails with "device not found" it just carries on anyway.We could bail out here if it returns an error, however, since we're running this speculatively it probably fails normally a lot (because the app isn't running).
The thing that runs next is
isAppInstalledwhich pretends the app is not installed if there are any errors:flutter/packages/flutter_tools/lib/src/android/android_device.dart
Lines 258 to 261 in 0fb2097
Possibly this should bail out (
throwToolExit?) in the case of an error; however I'm not sure if it's ever normal for this check to fail and we'd want to continue. I can try it and do some testing here, but I don't know if I can cover enough cases to be sure we're not going to start quitting on something we shouldn't.LMK what you think is best.
DanTup commentedon Jul 30, 2018
@devoncarew @gspencergoog Trying to clean up my list of issues - any opinions on the last comment above?
gspencergoog commentedon Aug 1, 2018
Can we check and see if the app is running before trying to stop it?
DanTup commentedon Sep 3, 2018
I don't know if that'll help - if I'm remembering/reading correctly, the issue isn't that
stopAppfails, it's that when it does, we just ignore that and carry on anyway. If we skipped overstop, we'd just be doing the same thing - continuing on and assuming the app is running.I think we need to detect that the app failed to install/launch and abort (ultimately terminating with a message that we failed to install).
zoechi commentedon Feb 18, 2019
@DanTup is this still relevant?
DanTup commentedon Feb 18, 2019
I think so, it doesn't look like the code around here has changed.
github-actions commentedon Jul 11, 2025
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 -vand a minimal reproduction of the issue.