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
ad540e4f
Unverified
Commit
ad540e4f
authored
Jun 24, 2021
by
Jonah Williams
Committed by
GitHub
Jun 24, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] retry chrome launch up to 3 times (#85162)
parent
e67113c1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
21 deletions
+69
-21
chrome.dart
packages/flutter_tools/lib/src/web/chrome.dart
+17
-8
chrome_test.dart
...ges/flutter_tools/test/general.shard/web/chrome_test.dart
+52
-13
No files found.
packages/flutter_tools/lib/src/web/chrome.dart
View file @
ad540e4f
...
...
@@ -249,7 +249,9 @@ class ChromiumLauncher {
// Keep attempting to launch the browser until one of:
// - Chrome launched successfully, in which case we just return from the loop.
// - The tool detected an unretriable Chrome error, in which case we throw ToolExit.
// - The tool reached the maximum retry count, in which case we throw ToolExit.
const
int
kMaxRetries
=
3
;
int
retry
=
0
;
while
(
true
)
{
final
Process
process
=
await
_processManager
.
start
(
args
);
...
...
@@ -263,6 +265,7 @@ class ChromiumLauncher {
// Wait until the DevTools are listening before trying to connect. This is
// only required for flutter_test --platform=chrome and not flutter run.
bool
hitGlibcBug
=
false
;
bool
shouldRetry
=
false
;
await
process
.
stderr
.
transform
(
utf8
.
decoder
)
.
transform
(
const
LineSplitter
())
...
...
@@ -270,6 +273,7 @@ class ChromiumLauncher {
_logger
.
printTrace
(
'[CHROME]:
$line
'
);
if
(
line
.
contains
(
_kGlibcError
))
{
hitGlibcBug
=
true
;
shouldRetry
=
true
;
}
return
line
;
})
...
...
@@ -282,17 +286,22 @@ class ChromiumLauncher {
// Return value unused.
return
''
;
}
_logger
.
printTrace
(
'Failed to launch browser. Command used to launch it:
${args.join(' ')}
'
);
throw
ToolExit
(
'Failed to launch browser. Make sure you are using an up-to-date '
'Chrome or Edge. Otherwise, consider using -d web-server instead '
'and filing an issue at https://github.com/flutter/flutter/issues.'
,
);
if
(
retry
>=
kMaxRetries
)
{
_logger
.
printTrace
(
'Failed to launch browser after
$kMaxRetries
tries. Command used to launch it:
${args.join(' ')}
'
);
throw
ToolExit
(
'Failed to launch browser. Make sure you are using an up-to-date '
'Chrome or Edge. Otherwise, consider using -d web-server instead '
'and filing an issue at https://github.com/flutter/flutter/issues.'
,
);
}
shouldRetry
=
true
;
return
''
;
});
if
(!
hitGlibcBug
)
{
if
(!
hitGlibcBug
&&
!
shouldRetry
)
{
return
process
;
}
retry
+=
1
;
// A precaution that avoids accumulating browser processes, in case the
// glibc bug doesn't cause the browser to quit and we keep looping and
...
...
packages/flutter_tools/test/general.shard/web/chrome_test.dart
View file @
ad540e4f
...
...
@@ -461,22 +461,61 @@ void main() {
);
});
testWithoutContext
(
'gives up retrying when a non-glibc error happens'
,
()
async
{
testWithoutContext
(
'can retry launch when chrome fails to start'
,
()
async
{
const
List
<
String
>
args
=
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0'
,
'--remote-debugging-port=12345'
,
...
kChromeArgs
,
'--headless'
,
'--disable-gpu'
,
'--no-sandbox'
,
'--window-size=2400,1800'
,
'example_url'
,
];
// Pretend to random error 3 times.
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
processManager
.
addCommand
(
const
FakeCommand
(
command:
args
,
stderr:
'BLAH BLAH'
,
));
}
// Succeed on the 4th try.
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0'
,
'--remote-debugging-port=12345'
,
...
kChromeArgs
,
'--headless'
,
'--disable-gpu'
,
'--no-sandbox'
,
'--window-size=2400,1800'
,
'example_url'
,
],
stderr:
'nothing in the std error indicating glibc error'
,
command:
args
,
stderr:
kDevtoolsStderr
,
));
expect
(
()
async
=>
chromeLauncher
.
launch
(
'example_url'
,
skipCheck:
true
,
headless:
true
,
),
returnsNormally
,
);
});
testWithoutContext
(
'gives up retrying when an error happens more than 3 times'
,
()
async
{
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
processManager
.
addCommand
(
const
FakeCommand
(
command:
<
String
>[
'example_chrome'
,
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0'
,
'--remote-debugging-port=12345'
,
...
kChromeArgs
,
'--headless'
,
'--disable-gpu'
,
'--no-sandbox'
,
'--window-size=2400,1800'
,
'example_url'
,
],
stderr:
'nothing in the std error indicating glibc error'
,
));
}
expect
(
()
async
=>
chromeLauncher
.
launch
(
'example_url'
,
...
...
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