Skip to content

flutter_tester is not terminated if SIGINT is sent during startup #20949

Closed

Description

@DanTup

I have a test in Dart Code that starts building a Flutter project and terminates it during build to ensure we clean up and close the debug session. I noticed it's leaking flutter_tester instances a lot.

Seems like if the SIGINT is sent at the right time, the flutter_tester process is not cleaned up. If you wait until the build finish, it does work correctly.

Possibly the issue is in stopApps() in resident_runner.dart; it seems to enumerate flutter views, but if the app hasn't finished loading yet, then probably this isn't going to clean it up.

Activity

  1. changed the title [-]flutter_tester is not terminated if SIGINT is sent during build[/-] [+]flutter_tester is not terminated if SIGINT is sent during startup[/+] on Aug 23, 2018
  2. added
    a: tests"flutter test", flutter_test, or one of our tests
    on Aug 23, 2018
  3. DanTup commented on Aug 23, 2018

    @DanTup
    ContributorAuthor

    Turns out the cleanup code isn't even running, because the signal handlers are only registered after the app has started:

    screen shot 2018-08-23 at 1 10 40 pm

  4. DanTup commented on Aug 23, 2018

    @DanTup
    ContributorAuthor

    @devoncarew @Hixie Any thoughts on how we'd like to fix this? Some thoughts:

    1. We could hook up the SIGINT/SIGTERM handlers earlier and then ensure they're resilient to the apps having not started (however, I'm not sure there's a "right" time to hook them up, if they're extended to clean up more in future for ex.)

    2. When we spawn the flutter_tester process, add our own SIGINT/SIGTERM handlers (inside FlutterTester that terminate the process)

    The second option seems most reliable, however it seems like a very specific fix when we might have many instances of this (lots of processes could be spawned during the build phase and others may suffer from not being terminated if you SIGINT before the app loads too).

    Actually, is this a Dart bug? In the docs for process.start it says:

    If mode is ProcessStartMode.detached a detached process will be created. A detached process has no connection to its parent, and can keep running on its own when the parent dies.

    This suggests to me that a non-detatched process (normal) should not keep running on its own when the parent dies. We're calling processManager.start and not passing a mode, and it's default is listed as normal.

  5. DanTup commented on Aug 23, 2018

    @DanTup
    ContributorAuthor

    I can repro this in a small script using flutter_tester, yet not with another process (eg. python) so I wonder whether there's something peculiar about flutter_tester.

    import 'dart:io';
    
    import 'package:process/process.dart';
    
    const String flutterPath = "/Users/dantup/Dev/Google/flutter";
    
    main() async {
      List<String> cmd = <String>[
        "$flutterPath/bin/cache/artifacts/engine/darwin-x64/flutter_tester",
        "--run-forever",
        "--non-interactive",
        "--enable-dart-profiling",
        "--packages=.packages",
        "--flutter-assets-dir=build/flutter_assets",
        "build/app.dill",
      ];
    
      final processManager = LocalProcessManager();
      await processManager.start(cmd,
          environment: <String, String>{
            'FLUTTER_TEST': 'true',
          },
          workingDirectory: "$flutterPath/examples/flutter_gallery");
      exit(1); // Or remove this and send a SIGTERM.. the flutter_tester process will remain
    }
  6. DanTup commented on Aug 23, 2018

    @DanTup
    ContributorAuthor

    I can't repro this from the terminal by running that exact command and then sending signals from another terminal (though honestly I'm not what the mechanism is for the child process quitting when the parent dies) so I'm not sure if this is an engine issue or a Dart issue.

    Does anyone know who might know about this?

  7. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Feb 13, 2019
  8. christopherfujino commented on Oct 28, 2021

    @christopherfujino
    Contributor

    @DanTup Hey thanks for this detailed investigation (3 years ago!). I ran into this and was wondering about it, and the minimal repro helps.

  9. DanTup commented on Oct 28, 2021

    @DanTup
    ContributorAuthor

    Happy to help

    (Unfortunately I have no idea how to fix it though :-))

  10. added
    P2Important issues not at the top of the work list
    P3Issues that are less important to the Flutter project
    and removed
    P2Important issues not at the top of the work list
    on Jan 25, 2022
  11. self-assigned this
    on Nov 19, 2024
  12. github-actions commented on Dec 3, 2024

    @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.

  13. locked as resolved and limited conversation to collaborators on Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: tests"flutter test", flutter_test, or one of our teststeam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions