Skip to content

Commit

Permalink
[flutter_tool] Retry a gradle build on connection timeout (#143084)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zanderso authored Feb 8, 2024
1 parent cc4abe9 commit fbc9f2d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/flutter_tools/lib/src/android/gradle_errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,16 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError(
@visibleForTesting
final GradleHandledError networkErrorHandler = GradleHandledError(
test: _lineMatcher(const <String>[
"> Could not get resource 'http",
'java.io.FileNotFoundException',
'java.io.FileNotFoundException: https://downloads.gradle.org',
'java.io.IOException: Unable to tunnel through proxy',
'java.io.IOException: Server returned HTTP response code: 502',
'java.io.IOException: Unable to tunnel through proxy',
'java.lang.RuntimeException: Timeout of',
'java.net.ConnectException: Connection timed out',
'java.net.SocketException: Connection reset',
'java.util.zip.ZipException: error in opening zip file',
'javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake',
'java.net.SocketException: Connection reset',
'java.io.FileNotFoundException',
"> Could not get resource 'http",
]),
handler: ({
required String line,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,40 @@ A problem occurred configuring root project 'android'.
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});

testUsingContext('retries if connection times out', () async {
const String errorMessage = r'''
Exception in thread "main" java.net.ConnectException: Connection timed out
java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:299)
at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:498)
at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:603)
at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)''';

expect(formatTestErrorMessage(errorMessage, networkErrorHandler), isTrue);
expect(await networkErrorHandler.handler(
line: '',
project: FakeFlutterProject(),
usesAndroidX: true,
), equals(GradleBuildStatus.retry));

expect(testLogger.errorText,
contains(
'Gradle threw an error while downloading artifacts from the network.'
)
);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
});

group('permission errors', () {
Expand Down

0 comments on commit fbc9f2d

Please sign in to comment.