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
2c94f2b4
Unverified
Commit
2c94f2b4
authored
Sep 11, 2019
by
Zachary Anderson
Committed by
GitHub
Sep 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tool] Kill a timing out process before trying to drain its stdout/err streams (#40159)
parent
e6ae95c4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
7 deletions
+36
-7
process.dart
packages/flutter_tools/lib/src/base/process.dart
+11
-4
process_test.dart
...s/flutter_tools/test/general.shard/base/process_test.dart
+25
-3
No files found.
packages/flutter_tools/lib/src/base/process.dart
View file @
2c94f2b4
...
...
@@ -275,13 +275,23 @@ Future<RunResult> runAsync(
int
exitCode
;
exitCode
=
await
process
.
exitCode
.
timeout
(
timeout
,
onTimeout:
()
{
// The process timed out. Kill it.
processManager
.
killPid
(
process
.
pid
);
return
null
;
});
String
stdoutString
;
String
stderrString
;
try
{
await
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutFuture
,
stderrFuture
]);
Future
<
void
>
stdioFuture
=
Future
.
wait
<
void
>(<
Future
<
void
>>[
stdoutFuture
,
stderrFuture
]);
if
(
exitCode
==
null
)
{
// If we had to kill the process for a timeout, only wait a short time
// for the stdio streams to drain in case killing the process didn't
// work.
stdioFuture
=
stdioFuture
.
timeout
(
const
Duration
(
seconds:
1
));
}
await
stdioFuture
;
}
catch
(
_
)
{
// Ignore errors on the process' stdout and stderr streams. Just capture
// whatever we got, and use the exit code
...
...
@@ -299,9 +309,6 @@ Future<RunResult> runAsync(
return
runResult
;
}
// The process timed out. Kill it.
processManager
.
killPid
(
process
.
pid
);
// If we are out of timeoutRetries, throw a ProcessException.
if
(
timeoutRetries
<
0
)
{
throw
ProcessException
(
cmd
[
0
],
cmd
.
sublist
(
1
),
...
...
packages/flutter_tools/test/general.shard/base/process_test.dart
View file @
2c94f2b4
...
...
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:async'
;
import
'package:flutter_tools/src/base/io.dart'
;
import
'package:flutter_tools/src/base/logger.dart'
;
import
'package:flutter_tools/src/base/platform.dart'
;
...
...
@@ -103,13 +105,13 @@ void main() {
// MockProcessManager has an implementation of start() that returns the
// result of processFactory.
flakyProcessManager
=
MockProcessManager
();
});
testUsingContext
(
'flaky process fails without retry'
,
()
async
{
flakyProcessManager
.
processFactory
=
flakyProcessFactory
(
flakes:
1
,
delay:
delay
,
);
});
testUsingContext
(
'flaky process fails without retry'
,
()
async
{
final
RunResult
result
=
await
runAsync
(
<
String
>[
'dummy'
],
timeout:
delay
+
const
Duration
(
seconds:
1
),
...
...
@@ -120,6 +122,10 @@ void main() {
});
testUsingContext
(
'flaky process succeeds with retry'
,
()
async
{
flakyProcessManager
.
processFactory
=
flakyProcessFactory
(
flakes:
1
,
delay:
delay
,
);
final
RunResult
result
=
await
runAsync
(
<
String
>[
'dummy'
],
timeout:
delay
-
const
Duration
(
milliseconds:
500
),
...
...
@@ -131,6 +137,22 @@ void main() {
});
testUsingContext
(
'flaky process generates ProcessException on timeout'
,
()
async
{
final
Completer
<
List
<
int
>>
flakyStderr
=
Completer
<
List
<
int
>>();
final
Completer
<
List
<
int
>>
flakyStdout
=
Completer
<
List
<
int
>>();
flakyProcessManager
.
processFactory
=
flakyProcessFactory
(
flakes:
1
,
delay:
delay
,
stderr:
()
=>
Stream
<
List
<
int
>>.
fromFuture
(
flakyStderr
.
future
),
stdout:
()
=>
Stream
<
List
<
int
>>.
fromFuture
(
flakyStdout
.
future
),
);
when
(
flakyProcessManager
.
killPid
(
any
)).
thenAnswer
((
_
)
{
// Don't let the stderr stream stop until the process is killed. This
// ensures that runAsync() does not delay killing the process until
// stdout and stderr are drained (which won't happen).
flakyStderr
.
complete
(<
int
>[]);
flakyStdout
.
complete
(<
int
>[]);
return
true
;
});
expect
(()
async
=>
await
runAsync
(
<
String
>[
'dummy'
],
timeout:
delay
-
const
Duration
(
milliseconds:
500
),
...
...
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