'I/O error on GET request for Try again; nested exception is java.net.UnknownHostException: Try again

Technologies: Java + Spring boot(2.5.2). I have upgraded my application from Java 8 to Java 11 (OpenJDK).

Previously I received below error so that I used do-while loop to retry until receive success response.

Java 8 - received success response less than 5 attempts

Java 11 - at 10th attempt also I am receiving same error

Error Log:

I/O error on POST request for "https://<externalurl>": <externalurl>; nested exception is java.net.UnknownHostException: <externalurl>

@Bean
    public RestTemplate restTemplate() {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setErrorHandler(new ResponseErrorHandler());
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setOutputStreaming(false);
        restTemplate.setRequestFactory(requestFactory);
        return restTemplate;
    }


Solution 1:[1]

Custom docker image with the combination of Alpine v3.11.3 and OpenJDK 11 working for me. There is some issue with DNS resolution in all other versions of Alpine (Latest version v3.15.0 also).

We will face similar issue in Debian OS - retry logic like sending same request again will work

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 dev4java