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
flutter_tester is not terminated if SIGINT is sent during startup #20949
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.
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
@devoncarew@Hixie Any thoughts on how we'd like to fix this? Some thoughts:
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.)
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.
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';
constString 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
}
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.
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.
Activity
[-]flutter_tester is not terminated if SIGINT is sent during build[/-][+]flutter_tester is not terminated if SIGINT is sent during startup[/+]DanTup commentedon Aug 23, 2018
Turns out the cleanup code isn't even running, because the signal handlers are only registered after the app has started:
DanTup commentedon Aug 23, 2018
@devoncarew @Hixie Any thoughts on how we'd like to fix this? Some thoughts:
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.)
When we spawn the
flutter_testerprocess, add our own SIGINT/SIGTERM handlers (insideFlutterTesterthat 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.startit says:This suggests to me that a non-detatched process (
normal) should not keep running on its own when the parent dies. We're callingprocessManager.startand not passing a mode, and it's default is listed asnormal.DanTup commentedon Aug 23, 2018
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 aboutflutter_tester.DanTup commentedon Aug 23, 2018
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?
Skip test that leaves flutter_test processes around
christopherfujino commentedon Oct 28, 2021
@DanTup Hey thanks for this detailed investigation (3 years ago!). I ran into this and was wondering about it, and the minimal repro helps.
DanTup commentedon Oct 28, 2021
(Unfortunately I have no idea how to fix it though :-))
Terminate the test device if the `flutter` tool is signal-killed. (#1…
github-actions commentedon Dec 3, 2024
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.