diff --git a/.kokoro/common.sh b/.kokoro/common.sh index 84e36200685f..cc937e2292d1 100644 --- a/.kokoro/common.sh +++ b/.kokoro/common.sh @@ -52,6 +52,20 @@ function retry_with_backoff { shift 2 command=("$@") + # Add defensive timeouts to Maven commands to prevent Kokoro VM timeouts (10800s hang) + local mvn_regex='(^|/)mvnw?$' + if [[ "${command[0]:-}" =~ $mvn_regex ]]; then + if [[ "${MAVEN_OPTS:-}" != *"-Daether.connector.requestTimeout"* ]]; then + local -x MAVEN_OPTS="${MAVEN_OPTS:+"$MAVEN_OPTS "}-Daether.connector.requestTimeout=300000" + MAVEN_OPTS+=" -Daether.connector.connectTimeout=30000" + MAVEN_OPTS+=" -Dmaven.wagon.rto=300000" + MAVEN_OPTS+=" -Dmaven.wagon.connectionTimeout=30000" + MAVEN_OPTS+=" -Dmaven.wagon.http.retryHandler.class=standard" + MAVEN_OPTS+=" -Dmaven.wagon.http.retryHandler.count=3" + MAVEN_OPTS+=" -Dmaven.wagon.httpconnectionManager.ttlSeconds=120" + fi + fi + # store current flag state flags=$-