我们有一个maven构建,在亚马逊ec2实例中的jenkins中运行。 总构建需要20-30分钟,并且大致每次运行它都会失败,因为它无法从maven中心下载工件。这是日志的失败部分:
ERROR: 2017/02/03 13:41:23 page.go:555: Failed to parse date '`r format(Sys.Date(), "%Y-%m-%d")`' in page post/x.html
有趣的是,它从maven central和我们自己的repos下载20分钟运行正常,但是每隔一段时间就完全相同的下载失败了。这让我觉得它不是由于连接问题,因为它会在其他下载中随机失败。
谷歌搜索后我发现可能是因为Ipv4与Ipv6问题,所以我尝试在构建中设置java.net.prefetIPv4stack = true,但这没有用。
运行mvn的命令是:
[DEBUG] Lifecycle default -> [validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy]
[DEBUG] Lifecycle clean -> [pre-clean, clean, post-clean]
[DEBUG] Lifecycle site -> [pre-site, site, post-site, site-deploy]
[DEBUG] Using transporter WagonTransporter with priority -1.0 for https://repo.maven.apache.org/maven2
[DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for https://repo.maven.apache.org/maven2
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-failsafe-plugin/2.18.1/maven-failsafe-plugin-2.18.1.pom
Feb 03, 2017 3:39:00 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Connection reset
Feb 03, 2017 3:39:00 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Feb 03, 2017 3:39:00 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Connection reset
Feb 03, 2017 3:39:00 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Feb 03, 2017 3:39:00 PM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Connection reset
Feb 03, 2017 3:39:00 PM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
我还尝试在MAVEN_OPTS和JAVA_OPTS中增加-Xmx(我在某处读到maven需要能够将所有依赖关系保存在RAM中,不确定是否真的如此),但没有成功。
你还有其他想法吗?
编辑:添加了堆栈跟踪
mvn -X -e clean deploy -U -Djava.net.preferIPv4Stack=true
答案 0 :(得分:1)
很少指针,
1)这看起来是EC2网络设置问题。这不是maven http旅行车的问题。
3)您可以暂时尝试以下。
sudo sysctl -w net.ipv4.tcp_keepalive_time=60
sudo sysctl -w net.ipv4.tcp_keepalive_intvl=60
sudo sysctl -w net.ipv4.tcp_keepalive_probes=10
希望它可以帮助您解决问题。
答案 1 :(得分:0)
Azure VM中存在类似问题。我也在这里发布了这个问题:Maven build download artefacts connection slow/reset when running inside a Docker Container on Azure
我们的设置有点复杂-我们运行了一个docker容器,其中包括maven的构建步骤。
在ACI和Azure VM中运行容器时-我们都遇到相同的问题,Maven Central下载超时或成功,但速度非常慢。
studentID= 'RSL333444'
通知可疑者:( 159 B / s时为151 kB),(84 B / s时为80 kB),(788 B / s时为744 kB) 我们提供了可以正常运行的执行示例-以及超时(1小时)的执行示例-以及耗时接近1小时的执行示例。
我们尝试更改mvn命令-我们最初运行:
14:10:48,505 [BasicRepositoryConnector-repo.maven.apache.org-27-0] [INFO] Downloading from central: https://repo.maven.apache.org/maven2/regexp/regexp/1.3/regexp-1.3.jar
14:10:48,506 [BasicRepositoryConnector-repo.maven.apache.org-27-2] [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/scm/maven-scm-provider-cvs-commons/1.7/maven-scm-provider-cvs-commons-1.7.jar
14:10:48,505 [BasicRepositoryConnector-repo.maven.apache.org-27-1] [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/scm/maven-scm-provider-git-commons/1.7/maven-scm-provider-git-commons-1.7.jar
14:10:48,521 [BasicRepositoryConnector-repo.maven.apache.org-27-3] [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/tmatesoft/sqljet/sqljet/1.0.4/sqljet-1.0.4.jar
14:10:48,523 [BasicRepositoryConnector-repo.maven.apache.org-27-4] [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar
14:10:48,540 [BasicRepositoryConnector-repo.maven.apache.org-27-0] [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/regexp/regexp/1.3/regexp-1.3.jar (25 kB at 706 kB/s)
14:10:48,540 [BasicRepositoryConnector-repo.maven.apache.org-27-0] [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/antlr/stringtemplate/3.2/stringtemplate-3.2.jar
14:10:48,564 [BasicRepositoryConnector-repo.maven.apache.org-27-0] [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/stringtemplate/3.2/stringtemplate-3.2.jar (172 kB at 4.0 MB/s)
14:26:32,150 [BasicRepositoryConnector-repo.maven.apache.org-27-2] [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/scm/maven-scm-provider-cvs-commons/1.7/maven-scm-provider-cvs-commons-1.7.jar (80 kB at 84 B/s)
14:26:32,157 [BasicRepositoryConnector-repo.maven.apache.org-27-4] [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/antlr/antlr-runtime/3.1.3/antlr-runtime-3.1.3.jar (151 kB at 159 B/s)
14:26:32,199 [BasicRepositoryConnector-repo.maven.apache.org-27-3] [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/tmatesoft/sqljet/sqljet/1.0.4/sqljet-1.0.4.jar (744 kB at 788 B/s)
但是我们添加了:
mvn clean package
mvn compile dependency:resolve
mvn dependency:resolve-plugin
这些更改仅改变了连接变慢的位置-而不是下载一些jar,而是在下载.pom文件时变慢了。
答案 2 :(得分:0)
TL; DR
尝试升级到Maven 3.6.1。它具有经过改进的重试行为的Wagon HTTP新版本。这为我们解决了这个问题。
背景
我们的版本运行了好几个月(在ec2中)。然后,有一天,他们开始偶发性地失败,并从Connection重置中下载了Maven工件(从Maven Central)。我们从来没有深入了解它。也许ec2中的某些内容发生了变化。也许我们的构建发生了变化。不知道。
最重要的是,网络不可靠,并且Maven(或更具体地说是Wagon)对连接失败的适应性不是很强。幸运的是,看起来他们已经对此进行了改进。
Maven 3.6.1包含支持可配置重试行为的Wagon新版本。默认情况下,它的重试次数似乎为3-对我们来说足够了。一些细节: