Skip to content

Commit fbc9f2d

Browse files
authored
[flutter_tool] Retry a gradle build on connection timeout (#143084)
This PR will likely not help with the issue on our CI discussed in flutter/flutter#142637, but will do one retry for our users if they hit the same issue.
1 parent cc4abe9 commit fbc9f2d

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

packages/flutter_tools/lib/src/android/gradle_errors.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,16 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
112112
@visibleForTesting
113113
final GradleHandledError networkErrorHandler = GradleHandledError(
114114
test: _lineMatcher(const <String>[
115+
"> Could not get resource 'http",
116+
'java.io.FileNotFoundException',
115117
'java.io.FileNotFoundException: https://downloads.gradle.org',
116-
'java.io.IOException: Unable to tunnel through proxy',
117118
'java.io.IOException: Server returned HTTP response code: 502',
119+
'java.io.IOException: Unable to tunnel through proxy',
118120
'java.lang.RuntimeException: Timeout of',
121+
'java.net.ConnectException: Connection timed out',
122+
'java.net.SocketException: Connection reset',
119123
'java.util.zip.ZipException: error in opening zip file',
120124
'javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake',
121-
'java.net.SocketException: Connection reset',
122-
'java.io.FileNotFoundException',
123-
"> Could not get resource 'http",
124125
]),
125126
handler: ({
126127
required String line,

packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,40 @@ A problem occurred configuring root project 'android'.
407407
FileSystem: () => fileSystem,
408408
ProcessManager: () => processManager,
409409
});
410+
411+
testUsingContext('retries if connection times out', () async {
412+
const String errorMessage = r'''
413+
Exception in thread "main" java.net.ConnectException: Connection timed out
414+
java.base/sun.nio.ch.Net.connect0(Native Method)
415+
at java.base/sun.nio.ch.Net.connect(Net.java:579)
416+
at java.base/sun.nio.ch.Net.connect(Net.java:568)
417+
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
418+
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
419+
at java.base/java.net.Socket.connect(Socket.java:633)
420+
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:299)
421+
at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
422+
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
423+
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:498)
424+
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:603)
425+
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
426+
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)''';
427+
428+
expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
429+
expect(await networkErrorHandler.handler(
430+
line: '',
431+
project: FakeFlutterProject(),
432+
usesAndroidX: true,
433+
), equals(GradleBuildStatus.retry));
434+
435+
expect(testLogger.errorText,
436+
contains(
437+
'Gradle threw an error while downloading artifacts from the network.'
438+
)
439+
);
440+
}, overrides: <Type, Generator>{
441+
FileSystem: () => fileSystem,
442+
ProcessManager: () => processManager,
443+
});
410444
});
411445

412446
group('permission errors', () {

0 commit comments

Comments
 (0)