Skip to content

Cannot retry request with a non-repeatable request entity #38

@dblock

Description

@dblock

Coming from amazon-archives/aws-request-signing-apache-interceptor#7 request retries aren't working in the current implementation either, but for a different reason, cc: @chudinovskikh, @noslowerdna.

To reproduce, replace signingClientForServiceName with one that throws an IOException the first time around.

    CloseableHttpClient signingClientForServiceName(String serviceName, Region region) {
        Aws4Signer signer = Aws4Signer.create();

        HttpRequestInterceptor interceptor = new AwsRequestSigningApacheInterceptor(serviceName, signer,
                credentialsProvider, region);

        return HttpClients.custom()
                .addInterceptorLast(interceptor)
                .addInterceptorLast(new HttpRequestInterceptor() {
                    private int exceptionCount = 0;

                    @Override
                    public void process(HttpRequest request, HttpContext context)
                            throws HttpException, IOException {
                                if (exceptionCount++ <= 0) {
                                    throw new IOException("Planned");                        
                                }
                    }
                }).build();
    }

dblock@454345b

mvn test-compile exec:java -Dexec.classpathScope=test -Dexec.mainClass="io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample"

...
2022/07/07 11:04:05:417 BRT [INFO] RetryExec - I/O exception (java.io.IOException) caught when processing request to {s}->https://search-dblock-test-opensearch-21-tu5gqrjd4vg4qazjsu6bps5zsy.us-west-2.es.amazonaws.com:443: Planned
[WARNING] 
org.apache.http.client.ClientProtocolException
    at org.apache.http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:187)
    at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:108)
    at io.github.acm19.aws.interceptor.test.Sample.logRequest (Sample.java:65)
    at io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample.indexDocument (AmazonOpenSearchServiceSample.java:91)
    at io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample.main (AmazonOpenSearchServiceSample.java:74)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:833)
Caused by: org.apache.http.client.NonRepeatableRequestException: Cannot retry request with a non-repeatable request entity
    at org.apache.http.impl.execchain.RetryExec.execute (RetryExec.java:108)
    at org.apache.http.impl.execchain.RedirectExec.execute (RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:108)
    at io.github.acm19.aws.interceptor.test.Sample.logRequest (Sample.java:65)
    at io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample.indexDocument (AmazonOpenSearchServiceSample.java:91)
    at io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample.main (AmazonOpenSearchServiceSample.java:74)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:833)
Caused by: java.io.IOException: Planned
    at io.github.acm19.aws.interceptor.test.Sample$1.process (Sample.java:102)
    at org.apache.http.protocol.ImmutableHttpProcessor.process (ImmutableHttpProcessor.java:133)
    at org.apache.http.impl.execchain.ProtocolExec.execute (ProtocolExec.java:184)
    at org.apache.http.impl.execchain.RetryExec.execute (RetryExec.java:89)
    at org.apache.http.impl.execchain.RedirectExec.execute (RedirectExec.java:110)
    at org.apache.http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:185)
    at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83)
    at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:108)
    at io.github.acm19.aws.interceptor.test.Sample.logRequest (Sample.java:65)
    at io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample.indexDocument (AmazonOpenSearchServiceSample.java:91)
    at io.github.acm19.aws.interceptor.test.AmazonOpenSearchServiceSample.main (AmazonOpenSearchServiceSample.java:74)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:833)

Fix in #39.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions