From fbc9f2d5bf6b530d24b7f27c628b2401a23ea630 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Thu, 8 Feb 2024 12:39:00 -0800 Subject: [PATCH] [flutter_tool] Retry a gradle build on connection timeout (#143084) This PR will likely not help with the issue on our CI discussed in https://github.com/flutter/flutter/issues/142637, but will do one retry for our users if they hit the same issue. --- .../lib/src/android/gradle_errors.dart | 9 ++--- .../android/gradle_errors_test.dart | 34 +++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/gradle_errors.dart b/packages/flutter_tools/lib/src/android/gradle_errors.dart index 75fb68a620..4bc3efaae3 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -112,15 +112,16 @@ final GradleHandledError permissionDeniedErrorHandler = GradleHandledError( @visibleForTesting final GradleHandledError networkErrorHandler = GradleHandledError( test: _lineMatcher(const [ + "> 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, diff --git a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart index f07f31e192..0669159660 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart @@ -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.(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: { + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }); }); group('permission errors', () {