Unverified Commit d2f70a6d authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

kill leaked chrome processes (#39514)

parent 14cec30c
...@@ -14,7 +14,7 @@ class RunningProcessInfo { ...@@ -14,7 +14,7 @@ class RunningProcessInfo {
assert(commandLine != null); assert(commandLine != null);
final String commandLine; final String commandLine;
final int pid; final String pid;
final DateTime creationDate; final DateTime creationDate;
@override @override
...@@ -47,7 +47,7 @@ class RunningProcessInfo { ...@@ -47,7 +47,7 @@ class RunningProcessInfo {
} }
} }
Future<bool> killProcess(int pid, {ProcessManager processManager}) async { Future<bool> killProcess(String pid, {ProcessManager processManager}) async {
assert(pid != null, 'Must specify a pid to kill'); assert(pid != null, 'Must specify a pid to kill');
processManager ??= const LocalProcessManager(); processManager ??= const LocalProcessManager();
ProcessResult result; ProcessResult result;
...@@ -55,14 +55,14 @@ Future<bool> killProcess(int pid, {ProcessManager processManager}) async { ...@@ -55,14 +55,14 @@ Future<bool> killProcess(int pid, {ProcessManager processManager}) async {
result = await processManager.run(<String>[ result = await processManager.run(<String>[
'taskkill.exe', 'taskkill.exe',
'/pid', '/pid',
pid.toString(), pid,
'/f', '/f',
]); ]);
} else { } else {
result = await processManager.run(<String>[ result = await processManager.run(<String>[
'kill', 'kill',
'-9', '-9',
pid.toString(), pid,
]); ]);
} }
return result.exitCode == 0; return result.exitCode == 0;
...@@ -163,7 +163,7 @@ Iterable<RunningProcessInfo> processPowershellOutput(String output) sync* { ...@@ -163,7 +163,7 @@ Iterable<RunningProcessInfo> processPowershellOutput(String output) sync* {
time = '${hours + 12}${time.substring(2)}'; time = '${hours + 12}${time.substring(2)}';
} }
final int pid = int.parse(line.substring(0, processIdHeaderSize).trim()); final String pid = line.substring(0, processIdHeaderSize).trim();
final DateTime creationDate = DateTime.parse('$year-$month-${day}T$time'); final DateTime creationDate = DateTime.parse('$year-$month-${day}T$time');
final String commandLine = line.substring(commandLineHeaderStart).trim(); final String commandLine = line.substring(commandLineHeaderStart).trim();
yield RunningProcessInfo(pid, creationDate, commandLine); yield RunningProcessInfo(pid, creationDate, commandLine);
...@@ -254,7 +254,7 @@ Iterable<RunningProcessInfo> processPsOutput( ...@@ -254,7 +254,7 @@ Iterable<RunningProcessInfo> processPsOutput(
final DateTime creationDate = DateTime.parse('$year-$month-${day}T$time'); final DateTime creationDate = DateTime.parse('$year-$month-${day}T$time');
line = line.substring(24).trim(); line = line.substring(24).trim();
final int nextSpace = line.indexOf(' '); final int nextSpace = line.indexOf(' ');
final int pid = int.parse(line.substring(0, nextSpace)); final String pid = line.substring(0, nextSpace);
final String commandLine = line.substring(nextSpace + 1); final String commandLine = line.substring(nextSpace + 1);
yield RunningProcessInfo(pid, creationDate, commandLine); yield RunningProcessInfo(pid, creationDate, commandLine);
} }
......
...@@ -9,6 +9,7 @@ import 'dart:io'; ...@@ -9,6 +9,7 @@ import 'dart:io';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import '../framework/framework.dart'; import '../framework/framework.dart';
import '../framework/running_processes.dart';
import '../framework/utils.dart'; import '../framework/utils.dart';
final Directory _editedFlutterGalleryDir = dir(path.join(Directory.systemTemp.path, 'edited_flutter_gallery')); final Directory _editedFlutterGalleryDir = dir(path.join(Directory.systemTemp.path, 'edited_flutter_gallery'));
...@@ -20,6 +21,18 @@ TaskFunction createWebDevModeTest() { ...@@ -20,6 +21,18 @@ TaskFunction createWebDevModeTest() {
'--hot', '-d', 'chrome', '--verbose', '--resident', '--target=lib/main.dart', '--hot', '-d', 'chrome', '--verbose', '--resident', '--target=lib/main.dart',
]; ];
int hotRestartCount = 0; int hotRestartCount = 0;
String chromeProcessName;
if (Platform.isMacOS) {
chromeProcessName = 'Chrome';
} else if (Platform.isLinux) {
chromeProcessName = 'chrome';
} else if (Platform.isWindows) {
chromeProcessName = 'chrome.exe';
}
final Set<String> beforeChromeProcesses = await getRunningProcesses(processName: chromeProcessName)
.map((RunningProcessInfo info) => info.pid)
.toSet();
try {
await inDirectory<void>(flutterDirectory, () async { await inDirectory<void>(flutterDirectory, () async {
rmTree(_editedFlutterGalleryDir); rmTree(_editedFlutterGalleryDir);
mkdirs(_editedFlutterGalleryDir); mkdirs(_editedFlutterGalleryDir);
...@@ -133,6 +146,15 @@ TaskFunction createWebDevModeTest() { ...@@ -133,6 +146,15 @@ TaskFunction createWebDevModeTest() {
} }
}); });
}); });
} finally {
final Set<String> afterChromeProcesses = await getRunningProcesses(processName: chromeProcessName)
.map((RunningProcessInfo info) => info.pid)
.toSet();
final Set<String> newProcesses = afterChromeProcesses.difference(beforeChromeProcesses);
for (String processId in newProcesses) {
await killProcess(processId);
}
}
if (hotRestartCount != 1) { if (hotRestartCount != 1) {
return TaskResult.failure(null); return TaskResult.failure(null);
} }
......
...@@ -24,17 +24,17 @@ ProcessId CreationDate CommandLine ...@@ -24,17 +24,17 @@ ProcessId CreationDate CommandLine
results, results,
equals(<RunningProcessInfo>[ equals(<RunningProcessInfo>[
RunningProcessInfo( RunningProcessInfo(
6552, '6552',
DateTime(2019, 7, 3, 17, 0, 27), DateTime(2019, 7, 3, 17, 0, 27),
r'"C:\tools\dart-sdk\bin\dart.exe" .\bin\agent.dart ci', r'"C:\tools\dart-sdk\bin\dart.exe" .\bin\agent.dart ci',
), ),
RunningProcessInfo( RunningProcessInfo(
6553, '6553',
DateTime(2019, 7, 3, 22, 0, 27), DateTime(2019, 7, 3, 22, 0, 27),
r'"C:\tools\dart-sdk1\bin\dart.exe" .\bin\agent.dart ci', r'"C:\tools\dart-sdk1\bin\dart.exe" .\bin\agent.dart ci',
), ),
RunningProcessInfo( RunningProcessInfo(
6554, '6554',
DateTime(2019, 7, 3, 11, 0, 27), DateTime(2019, 7, 3, 11, 0, 27),
r'"C:\tools\dart-sdk2\bin\dart.exe" .\bin\agent.dart ci', r'"C:\tools\dart-sdk2\bin\dart.exe" .\bin\agent.dart ci',
), ),
...@@ -54,12 +54,12 @@ Sat Mar 9 20:13:00 2019 49 /usr/sbin/syslogd ...@@ -54,12 +54,12 @@ Sat Mar 9 20:13:00 2019 49 /usr/sbin/syslogd
results, results,
equals(<RunningProcessInfo>[ equals(<RunningProcessInfo>[
RunningProcessInfo( RunningProcessInfo(
1, '1',
DateTime(2019, 3, 9, 20, 12, 47), DateTime(2019, 3, 9, 20, 12, 47),
'/sbin/launchd', '/sbin/launchd',
), ),
RunningProcessInfo( RunningProcessInfo(
49, '49',
DateTime(2019, 3, 9, 20, 13, 00), DateTime(2019, 3, 9, 20, 13, 00),
'/usr/sbin/syslogd', '/usr/sbin/syslogd',
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment