Skip to content

flutter run does not terminate after failure to install #11103

Closed as not planned

Description

@DanTup

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?

Activity

  1. added
    tool
    on May 1, 2018
  2. added this to the milestone on May 1, 2018
  3. Hixie commented on May 1, 2018

    @Hixie
    Contributor

    @DanTup What's the status of this one, do you know?

  4. DanTup commented on May 2, 2018

    @DanTup
    ContributorAuthor

    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.

  5. self-assigned this
    on May 2, 2018
  6. DanTup commented on Jun 21, 2018

    @DanTup
    ContributorAuthor

    This is still a problem. In some cases it doesn't even send a stop notification. I don't think the case linked above will help, since it's not clear if/when we should terminate the process.

    Dart Code extension: 2.15.0-beta.1
    Platform: mac
    Workspace type: Flutter
    Multi-root?: false
    Dart SDK:
        Loc: /Users/dantup/Dev/Google/flutter/bin/cache/dart-sdk
        Ver: 2.0.0-edge.4b2d60cb18e418c5cb92cf22d2d959d8b70142a3
    Flutter SDK:
        Loc: /Users/dantup/Dev/Google/flutter
        Ver: 0.5.6-pre.30
    
    Thu Jun 21 2018 [14:25:38 GMT+0100 (BST)] Log file started
    [14:25:44 GMT+0100 (BST)] [FlutterRun] Spawning /Users/dantup/Dev/Google/flutter/bin/flutter with args ["run","--machine","-t","lib/main.dart","-d","ZY2224Z9N9","--start-paused"]
    [14:25:44 GMT+0100 (BST)] [FlutterRun] ..  in /Users/dantup/Dev/Google/flutter/examples/stocks
    [14:25:46 GMT+0100 (BST)] [FlutterRun] <== [{"event":"daemon.connected","params":{"version":"0.3.0","pid":1650}}]
    [14:25:46 GMT+0100 (BST)] [FlutterRun] <== [{"event":"app.start","params":{"appId":"4e00e576-9cb0-4b30-8a57-9b19880aa590","deviceId":"ZY2224Z9N9","directory":"/Users/dantup/Dev/Google/flutter/examples/stocks","supportsRestart":true}}]
    [14:25:46 GMT+0100 (BST)] [FlutterRun] <== Launching lib/main.dart on XT1562 in debug mode...
    [14:25:46 GMT+0100 (BST)] [FlutterRun] <== [{"event":"app.progress","params":{"appId":"4e00e576-9cb0-4b30-8a57-9b19880aa590","id":"0","progressId":null,"message":"Initializing gradle..."}}]
    [14:25:48 GMT+0100 (BST)] [FlutterRun] <== [{"event":"app.progress","params":{"appId":"4e00e576-9cb0-4b30-8a57-9b19880aa590","id":"0","progressId":null,"finished":true}}]
    [14:25:48 GMT+0100 (BST)] [FlutterRun] <== [{"event":"app.progress","params":{"appId":"4e00e576-9cb0-4b30-8a57-9b19880aa590","id":"1","progressId":null,"message":"Resolving dependencies..."}}]
    [14:25:56 GMT+0100 (BST)] [FlutterRun] <== [{"event":"app.progress","params":{"appId":"4e00e576-9cb0-4b30-8a57-9b19880aa590","id":"1","progressId":null,"finished":true}}]
    Thu Jun 21 2018 [14:26:31 GMT+0100 (BST)] Log file ended
    

    However I don't think it's isolated to --machine.. I left this for many minutes:

    screen shot 2018-06-21 at 2 31 12 pm

  7. changed the title [-]`flutter run --machine` does not terminate after failure to install[/-] [+]`flutter run` does not terminate after failure to install[/+] on Jun 21, 2018
  8. DanTup commented on Jun 21, 2018

    @DanTup
    ContributorAuthor

    @devoncarew The errors above come seem to come from AppDomain in daemon.dart, where we have this in handleCommand:

    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 daemon we shouldn't, but for flutter run it 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..

  9. DanTup commented on Jun 27, 2018

    @DanTup
    ContributorAuthor

    @devoncarew Ok, I think I finally got to the bottom of why this is happening.. adb outputs message that look exactly like the ones in flutter_tools (device 'x' not found.); these messages are coming from there. We have many places that call adb and print its stdout/stderr.

    In the case I was testing, this is occurring in this code:

    printTrace("Stopping app '${package.name}' on $name.");
    await stopApp(package);

    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 is false in 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 isAppInstalled which pretends the app is not installed if there are any errors:

    } catch (error) {
    printTrace('$error');
    return false;
    }

    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.

  10. DanTup commented on Jul 30, 2018

    @DanTup
    ContributorAuthor

    @devoncarew @gspencergoog Trying to clean up my list of issues - any opinions on the last comment above?

  11. gspencergoog commented on Aug 1, 2018

    @gspencergoog
    Contributor

    Can we check and see if the app is running before trying to stop it?

  12. DanTup commented on Sep 3, 2018

    @DanTup
    ContributorAuthor

    I don't know if that'll help - if I'm remembering/reading correctly, the issue isn't that stopApp fails, it's that when it does, we just ignore that and carry on anyway. If we skipped over stop, 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).

  13. removed their assignment
    on Oct 2, 2018
  14. zoechi commented on Feb 18, 2019

    @zoechi
    Contributor

    @DanTup is this still relevant?

  15. DanTup commented on Feb 18, 2019

    @DanTup
    ContributorAuthor

    I think so, it doesn't look like the code around here has changed.

  16. assigned and unassigned on Jan 3, 2020
  17. added
    P2
    on May 29, 2020
  18. removed this from the milestone on Jun 2, 2020
  19. removed this from the milestone on Jun 2, 2020
  20. removed this from the milestone on Aug 17, 2020
  21. added
    team-tool
    triaged-tool
    on Jul 8, 2023
  22. github-actions commented on Jul 11, 2025

    @github-actions

    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 -v and a minimal reproduction of the issue.

  23. locked as resolved and limited conversation to collaborators on Jul 11, 2025
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

    P2team-tooltooltriaged-tool

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions