tycho icon indicating copy to clipboard operation
tycho copied to clipboard

Add retry support for HTTP 503/429 to Java11HttpTransport with Maven Resolver compatibility

Open Copilot opened this issue 2 months ago • 2 comments

The Java11 HTTP transport lacked retry logic for transient server failures (503 Service Unavailable) and rate limiting (429 Too Many Requests), causing builds to fail unnecessarily when encountering temporary service interruptions.

Changes

Modified: Java11HttpTransportFactory.java

  • Retry logic for 503 and 429: Both performGet() and doHead() now retry up to 3 times (configurable) on these status codes
  • Retry-After header parsing: Supports both integer seconds ("10") and HTTP date formats (RFC 1123/1036/ANSI C)
  • Fallback delay: Uses 5 seconds when Retry-After header is absent or unparsable
  • Resource cleanup: Response streams are properly closed before each retry attempt
  • Logging: Emits info-level messages showing status code, delay, and remaining retries
  • Maven Resolver compatibility: Supports aether.connector.http.retryHandler.count and aether.connector.http.retryHandler.interval properties for configuration

Configuration

Users can configure retry behavior using Maven Resolver standard properties:

<properties>
  <!-- Set retry attempts (default: 3) -->
  <aether.connector.http.retryHandler.count>5</aether.connector.http.retryHandler.count>
  
  <!-- Set retry delay in milliseconds (default: 5000) -->
  <aether.connector.http.retryHandler.interval>10000</aether.connector.http.retryHandler.interval>
</properties>

Or via command line:

mvn clean install -Daether.connector.http.retryHandler.count=5

Implementation

private <T> T performGet(ResponseConsumer<T> consumer, HttpClient httpClient) {
    int retriesLeft = maxRetryAttempts;  // Configurable via Maven properties
    while (retriesLeft > 0) {
        retriesLeft--;
        HttpResponse<InputStream> response = httpClient.send(request, ...);
        
        int statusCode = response.statusCode();
        if (shouldRetry(statusCode) && retriesLeft > 0) {
            long delaySeconds = getRetryDelay(response);
            logger.info("Server returned status " + statusCode + " for " + uri 
                    + ", waiting " + delaySeconds + " seconds before retry. " 
                    + retriesLeft + " retries left.");
            // Clean up and retry
            TimeUnit.SECONDS.sleep(delaySeconds);
            continue;
        }
        return consumer.handleResponse(new ResponseImplementation<>(response));
    }
    throw new IOException("Maximum retry attempts exceeded for " + uri);
}

Aligns with Maven Resolver configuration standards and follows the same pattern as existing retry logic in PGPService.

Original prompt

Add retry support to Tycho Jdk11 transport

We have teh JDk11 Http transport in Tycho and it should support

503 Service Unavailable 429 Too Many Requests

with Retry-After header and if that is not given uses 5 second delay and retry up to 5 times.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot avatar Nov 11 '25 07:11 Copilot

@copilot to align best with maven, we should support the following config properties from resolver where applicable in our implementation:

https://maven.apache.org/resolver/configuration.html

We should use https://github.com/eclipse-tycho/tycho/blob/main/tycho-spi/src/main/java/org/eclipse/tycho/helper/MavenPropertyHelper.java for that and also consider that maven is maybe using slightly different defaults see https://github.com/apache/maven/blob/master/impl/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java

laeubi avatar Nov 11 '25 08:11 laeubi

@copilot to align best with maven, we should support the following config properties from resolver where applicable in our implementation:

https://maven.apache.org/resolver/configuration.html ...

Updated in commit af8e2a0:

  • Added support for aether.connector.http.retryHandler.count property (default: 3 retries, matching Maven Resolver)
  • Added support for aether.connector.http.retryHandler.interval property (in milliseconds, default: 5000ms)
  • Integrated MavenPropertyHelper to read configuration from Maven session properties
  • Changed default retry count from 5 to 3 to align with Maven Resolver defaults

Users can now configure retry behavior via Maven properties or command line, e.g.:

mvn clean install -Daether.connector.http.retryHandler.count=5 -Daether.connector.http.retryHandler.interval=10000

Copilot avatar Nov 11 '25 08:11 Copilot