Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d2f70a6d
Unverified
Commit
d2f70a6d
authored
Aug 29, 2019
by
Jonah Williams
Committed by
GitHub
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kill leaked chrome processes (#39514)
parent
14cec30c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
117 deletions
+139
-117
running_processes.dart
dev/devicelab/lib/framework/running_processes.dart
+6
-6
web_dev_mode_tests.dart
dev/devicelab/lib/tasks/web_dev_mode_tests.dart
+128
-106
running_processes_test.dart
dev/devicelab/test/running_processes_test.dart
+5
-5
No files found.
dev/devicelab/lib/framework/running_processes.dart
View file @
d2f70a6d
...
...
@@ -14,7 +14,7 @@ class RunningProcessInfo {
assert
(
commandLine
!=
null
);
final
String
commandLine
;
final
int
pid
;
final
String
pid
;
final
DateTime
creationDate
;
@override
...
...
@@ -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'
);
processManager
??=
const
LocalProcessManager
();
ProcessResult
result
;
...
...
@@ -55,14 +55,14 @@ Future<bool> killProcess(int pid, {ProcessManager processManager}) async {
result
=
await
processManager
.
run
(<
String
>[
'taskkill.exe'
,
'/pid'
,
pid
.
toString
()
,
pid
,
'/f'
,
]);
}
else
{
result
=
await
processManager
.
run
(<
String
>[
'kill'
,
'-9'
,
pid
.
toString
()
,
pid
,
]);
}
return
result
.
exitCode
==
0
;
...
...
@@ -163,7 +163,7 @@ Iterable<RunningProcessInfo> processPowershellOutput(String output) sync* {
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
String
commandLine
=
line
.
substring
(
commandLineHeaderStart
).
trim
();
yield
RunningProcessInfo
(
pid
,
creationDate
,
commandLine
);
...
...
@@ -254,7 +254,7 @@ Iterable<RunningProcessInfo> processPsOutput(
final
DateTime
creationDate
=
DateTime
.
parse
(
'
$year
-
$month
-
${day}
T
$time
'
);
line
=
line
.
substring
(
24
).
trim
();
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
);
yield
RunningProcessInfo
(
pid
,
creationDate
,
commandLine
);
}
...
...
dev/devicelab/lib/tasks/web_dev_mode_tests.dart
View file @
d2f70a6d
...
...
@@ -9,6 +9,7 @@ import 'dart:io';
import
'package:path/path.dart'
as
path
;
import
'../framework/framework.dart'
;
import
'../framework/running_processes.dart'
;
import
'../framework/utils.dart'
;
final
Directory
_editedFlutterGalleryDir
=
dir
(
path
.
join
(
Directory
.
systemTemp
.
path
,
'edited_flutter_gallery'
));
...
...
@@ -20,119 +21,140 @@ TaskFunction createWebDevModeTest() {
'--hot'
,
'-d'
,
'chrome'
,
'--verbose'
,
'--resident'
,
'--target=lib/main.dart'
,
];
int
hotRestartCount
=
0
;
await
inDirectory
<
void
>(
flutterDirectory
,
()
async
{
rmTree
(
_editedFlutterGalleryDir
);
mkdirs
(
_editedFlutterGalleryDir
);
recursiveCopy
(
flutterGalleryDir
,
_editedFlutterGalleryDir
);
await
inDirectory
<
void
>(
_editedFlutterGalleryDir
,
()
async
{
{
final
Process
packagesGet
=
await
startProcess
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
<
String
>[
'packages'
,
'get'
],
environment:
<
String
,
String
>{
'FLUTTER_WEB'
:
'true'
,
},
);
await
packagesGet
.
exitCode
;
final
Process
process
=
await
startProcess
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
flutterCommandArgs
(
'run'
,
options
),
environment:
<
String
,
String
>{
'FLUTTER_WEB'
:
'true'
,
},
);
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
{
rmTree
(
_editedFlutterGalleryDir
);
mkdirs
(
_editedFlutterGalleryDir
);
recursiveCopy
(
flutterGalleryDir
,
_editedFlutterGalleryDir
);
await
inDirectory
<
void
>(
_editedFlutterGalleryDir
,
()
async
{
{
final
Process
packagesGet
=
await
startProcess
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
<
String
>[
'packages'
,
'get'
],
environment:
<
String
,
String
>{
'FLUTTER_WEB'
:
'true'
,
},
);
await
packagesGet
.
exitCode
;
final
Process
process
=
await
startProcess
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
flutterCommandArgs
(
'run'
,
options
),
environment:
<
String
,
String
>{
'FLUTTER_WEB'
:
'true'
,
},
);
final
Completer
<
void
>
stdoutDone
=
Completer
<
void
>();
final
Completer
<
void
>
stderrDone
=
Completer
<
void
>();
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
line
.
contains
(
'To hot restart'
))
{
process
.
stdin
.
write
(
'R'
);
}
if
(
line
.
contains
(
'Restarted'
))
{
if
(
hotRestartCount
==
0
)
{
// Update the file and reload again.
final
File
appDartSource
=
file
(
path
.
join
(
_editedFlutterGalleryDir
.
path
,
'lib/gallery/app.dart'
,
));
appDartSource
.
writeAsStringSync
(
appDartSource
.
readAsStringSync
().
replaceFirst
(
"'Flutter Gallery'"
,
"'Updated Flutter Gallery'"
,
)
);
process
.
stdin
.
writeln
(
'R'
);
++
hotRestartCount
;
}
else
{
// Quit after second hot restart.
process
.
stdin
.
writeln
(
'q'
);
final
Completer
<
void
>
stdoutDone
=
Completer
<
void
>();
final
Completer
<
void
>
stderrDone
=
Completer
<
void
>();
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
line
.
contains
(
'To hot restart'
))
{
process
.
stdin
.
write
(
'R'
);
}
}
print
(
'stdout:
$line
'
);
},
onDone:
()
{
stdoutDone
.
complete
();
});
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
print
(
'stderr:
$line
'
);
},
onDone:
()
{
stderrDone
.
complete
();
});
if
(
line
.
contains
(
'Restarted'
))
{
if
(
hotRestartCount
==
0
)
{
// Update the file and reload again.
final
File
appDartSource
=
file
(
path
.
join
(
_editedFlutterGalleryDir
.
path
,
'lib/gallery/app.dart'
,
));
appDartSource
.
writeAsStringSync
(
appDartSource
.
readAsStringSync
().
replaceFirst
(
"'Flutter Gallery'"
,
"'Updated Flutter Gallery'"
,
)
);
process
.
stdin
.
writeln
(
'R'
);
++
hotRestartCount
;
}
else
{
// Quit after second hot restart.
process
.
stdin
.
writeln
(
'q'
);
}
}
print
(
'stdout:
$line
'
);
},
onDone:
()
{
stdoutDone
.
complete
();
});
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
print
(
'stderr:
$line
'
);
},
onDone:
()
{
stderrDone
.
complete
();
});
await
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
,
]);
await
process
.
exitCode
;
await
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
,
]);
await
process
.
exitCode
;
}
}
// Start `flutter run` again to make sure it loads from the previous
// state. dev compilers loads up from previously compiled JavaScript.
{
final
Process
process
=
await
startProcess
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
flutterCommandArgs
(
'run'
,
options
),
environment:
<
String
,
String
>{
'FLUTTER_WEB'
:
'true'
,
},
);
final
Completer
<
void
>
stdoutDone
=
Completer
<
void
>();
final
Completer
<
void
>
stderrDone
=
Completer
<
void
>();
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
line
.
contains
(
'To hot restart'
))
{
process
.
stdin
.
write
(
'R'
);
}
if
(
line
.
contains
(
'Restarted'
))
{
process
.
stdin
.
writeln
(
'q'
);
}
print
(
'stdout:
$line
'
);
},
onDone:
()
{
stdoutDone
.
complete
();
});
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
print
(
'stderr:
$line
'
);
},
onDone:
()
{
stderrDone
.
complete
();
});
// Start `flutter run` again to make sure it loads from the previous
// state. dev compilers loads up from previously compiled JavaScript.
{
final
Process
process
=
await
startProcess
(
path
.
join
(
flutterDirectory
.
path
,
'bin'
,
'flutter'
),
flutterCommandArgs
(
'run'
,
options
),
environment:
<
String
,
String
>{
'FLUTTER_WEB'
:
'true'
,
},
);
final
Completer
<
void
>
stdoutDone
=
Completer
<
void
>();
final
Completer
<
void
>
stderrDone
=
Completer
<
void
>();
process
.
stdout
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
if
(
line
.
contains
(
'To hot restart'
))
{
process
.
stdin
.
write
(
'R'
);
}
if
(
line
.
contains
(
'Restarted'
))
{
process
.
stdin
.
writeln
(
'q'
);
}
print
(
'stdout:
$line
'
);
},
onDone:
()
{
stdoutDone
.
complete
();
});
process
.
stderr
.
transform
<
String
>(
utf8
.
decoder
)
.
transform
<
String
>(
const
LineSplitter
())
.
listen
((
String
line
)
{
print
(
'stderr:
$line
'
);
},
onDone:
()
{
stderrDone
.
complete
();
});
await
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
,
]);
await
process
.
exitCode
;
}
await
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutDone
.
future
,
stderrDone
.
future
,
]);
await
process
.
exitCode
;
}
});
});
});
}
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
)
{
return
TaskResult
.
failure
(
null
);
}
...
...
dev/devicelab/test/running_processes_test.dart
View file @
d2f70a6d
...
...
@@ -24,17 +24,17 @@ ProcessId CreationDate CommandLine
results
,
equals
(<
RunningProcessInfo
>[
RunningProcessInfo
(
6552
,
'6552'
,
DateTime
(
2019
,
7
,
3
,
17
,
0
,
27
),
r'"C:\tools\dart-sdk\bin\dart.exe" .\bin\agent.dart ci'
,
),
RunningProcessInfo
(
6553
,
'6553'
,
DateTime
(
2019
,
7
,
3
,
22
,
0
,
27
),
r'"C:\tools\dart-sdk1\bin\dart.exe" .\bin\agent.dart ci'
,
),
RunningProcessInfo
(
6554
,
'6554'
,
DateTime
(
2019
,
7
,
3
,
11
,
0
,
27
),
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
results
,
equals
(<
RunningProcessInfo
>[
RunningProcessInfo
(
1
,
'1'
,
DateTime
(
2019
,
3
,
9
,
20
,
12
,
47
),
'/sbin/launchd'
,
),
RunningProcessInfo
(
49
,
'49'
,
DateTime
(
2019
,
3
,
9
,
20
,
13
,
00
),
'/usr/sbin/syslogd'
,
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment