Repository: flutter
Issue: The gradle log line matcher meant to match network-induced zip file failures is not exhaustive
Labels: P2,c: tech-debt,team-tool,triaged-tool

See https://github.com/flutter/flutter/issues/142608, where CI failed due to network failures.

I see two unique errors here.

<details>

<summary>  Exception in thread "main" java.net.ConnectException: Connection timed out: connect  (NOTE: since addressed by #143084)</summary>**

```
[  +10 ms] executing: [C:\opt\s\w\ir\x\t\edited_flutter_gallery\android/] C:\opt\s\w\ir\x\t\edited_flutter_gallery\android\gradlew.bat --full-stacktrace --info -Pverbose=true --no-daemon -Ptarget-platform=android-arm -Ptarget=C:\opt\s\w\ir\x\t\edited_flutter_gallery\lib\main.dart -Pbase-application-name=android.app.Application -Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC80MzhlOWI0ZDdkNGU0MDMxMzc5YTkzMDI5NGI2YjJjNmZiYjgwNzljLw== -Pdart-obfuscation=false -Ptrack-widget-creation=true -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root assembleDebug
[2024-01-29 23:33:52.199551] [STDOUT] stdout: [ +330 ms] Downloading https://services.gradle.org/distributions/gradle-7.6.3-all.zip
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [+21968 ms] Exception in thread "main" java.net.ConnectException: Connection timed out: connect
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [   +1 ms] 	at java.base/sun.nio.ch.Net.connect0(Native Method)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.nio.ch.Net.connect(Net.java:579)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.nio.ch.Net.connect(Net.java:568)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:588)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/java.net.Socket.connect(Socket.java:633)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:299)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:174)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:183)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:498)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:603)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:189)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:175)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2887)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2796)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1927)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:224)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Download.download(Download.java:44)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install$1.call(Install.java:61)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install$1.call(Install.java:48)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install.createDist(Install.java:48)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
[2024-01-29 23:34:14.170894] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
[2024-01-29 23:34:14.201974] [STDOUT] stdout: [  +22 ms] Running Gradle task 'assembleDebug'... (completed in 22.3s)
[2024-01-29 23:34:14.201974] [STDOUT] stderr: [   +2 ms] Error: Gradle task assembleDebug failed with exit code 1
[2024-01-29 23:34:14.201974] [STDOUT] stdout: [   +2 ms] "flutter run" took 48,219ms.
[2024-01-29 23:34:14.201974] [STDOUT] stderr: [   +3 ms] 
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:809:9)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1388:27)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #4      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:354:9)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:294:5)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:119:9)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            #10     main (package:flutter_tools/executable.dart:90:3)
[2024-01-29 23:34:14.201974] [STDOUT] stderr:            <asynchronous suspension>
```

</details>

<details>

<summary>Exception in thread "main" java.util.zip.ZipException: zip END header not found</summary>

```
 executing: [C:\opt\s\w\ir\x\t\edited_flutter_gallery\android/] C:\opt\s\w\ir\x\t\edited_flutter_gallery\android\gradlew.bat --full-stacktrace --info -Pverbose=true --no-daemon -Ptarget-platform=android-arm -Ptarget=C:\opt\s\w\ir\x\t\edited_flutter_gallery\lib\main.dart -Pbase-application-name=android.app.Application -Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==,RkxVVFRFUl9XRUJfQ0FOVkFTS0lUX1VSTD1odHRwczovL3d3dy5nc3RhdGljLmNvbS9mbHV0dGVyLWNhbnZhc2tpdC82ODk0M2FmZDYyZDE1NjViMmY4NDg1ODFjYjM0MjkxNWNkMWEwOTE2Lw== -Pdart-obfuscation=false -Ptrack-widget-creation=true -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root assembleDebug
[2024-01-31 23:12:00.570561] [STDOUT] stdout: [ +147 ms] Downloading https://services.gradle.org/distributions/gradle-7.6.3-all.zip
[2024-01-31 23:26:14.205935] [STDOUT] stdout: [+853626 ms] ......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
[2024-01-31 23:26:14.205935] [STDOUT] stdout: [        ] Unzipping C:\opt\s\w\ir\cache\gradle\wrapper\dists\gradle-7.6.3-all\aocdy2d2z8kodnny3rsumj8i8\gradle-7.6.3-all.zip to C:\opt\s\w\ir\cache\gradle\wrapper\dists\gradle-7.6.3-all\aocdy2d2z8kodnny3rsumj8i8
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [  +12 ms] Exception in thread "main" java.util.zip.ZipException: zip END header not found
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [   +1 ms] 	at java.base/java.util.zip.ZipFile$Source.findEND(ZipFile.java:1469)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1477)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1315)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1277)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:709)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:243)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:172)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:186)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install.unzip(Install.java:214)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install.access$600(Install.java:27)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install$1.call(Install.java:74)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install$1.call(Install.java:48)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.Install.createDist(Install.java:48)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
[2024-01-31 23:26:14.221571] [STDOUT] stderr: [        ] 	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
[2024-01-31 23:26:14.252918] [STDOUT] stdout: [  +39 ms] Running Gradle task 'assembleDebug'... (completed in 853.8s)
[2024-01-31 23:26:14.268441] [STDOUT] stderr: [   +1 ms] Error: Gradle task assembleDebug failed with exit code 1
[2024-01-31 23:26:14.268441] [STDOUT] stdout: [   +1 ms] "flutter run" took 868,515ms.
[2024-01-31 23:26:14.268441] [STDOUT] stderr: [   +1 ms] 
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #0      throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #1      RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:819:9)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #2      FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1388:27)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #3      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #4      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #5      FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:354:9)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #6      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #7      FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:294:5)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #8      run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:119:9)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #9      AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:153:19)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            #10     main (package:flutter_tools/executable.dart:90:3)
[2024-01-31 23:26:14.268441] [STDOUT] stderr:            <asynchronous suspension>
[2024-01-31 23:26:14.268441] [STDOUT] stderr: 
```
</details>

These should probably be added to our [list of network-induced Gradle errors](https://github.com/andrewkolos/flutter/blob/6a6874ecf94d833b496b64b632c487c9f02ba9d3/packages/flutter_tools/lib/src/android/gradle_errors.dart#L113) when downloading artifacts so that the tool will retry if appropriate.

edit: ~~There's also a separate list of zip-related errors. @andrewkolos to investigate if that's even functioning correctly and if that should be used.~~

edit:

I believe we have a handle for the second case (ZipException: error in opening zip file): https://github.com/flutter/flutter/blob/6a6874ecf94d833b496b64b632c487c9f02ba9d3/packages/flutter_tools/lib/src/android/gradle_errors.dart#L151-L154

This handler (if running on a user machine (i.e not a bot)) will prompt the user for whether or not they would like to delete their `.gradle` directory. However, I suspect that this handler always gets preempted by `networkErrorHandler`: https://github.com/flutter/flutter/blob/6a6874ecf94d833b496b64b632c487c9f02ba9d3/packages/flutter_tools/lib/src/android/gradle_errors.dart#L151-L154.

If this is true, this is probably a bug. Is this `zipExceptionHandler` even necessary? It might be an artifact of an long-past issue.