Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321439

HttpClient execution fails when Astrill VPN is installed

XMLWordPrintable

    • x86_64
    • windows

      ADDITIONAL SYSTEM INFORMATION :
      Install Astrill VPN in the computer

      A DESCRIPTION OF THE PROBLEM :
      Simple execution of REST calls using HttpClient fails whenever Astrill VPN is installed in the computer.

      Same code can work in other computer.

      Based on the stack trace of the error, the issue happens at WindowsSelectorImpl doSelect method

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Install Astrill VPN in the Windows computer.
      2. Execute the HttpClientGet code

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      REST call is executed correctly, either with a success response or an error response from the server.
      ACTUAL -
      HttpClient throws an error

      Stack Trace:

      <debug> [HttpClient-1-SelectorManager] [717ms] HttpClientImpl(1) shutting down
      java.io.IOException: An exception occurred during the execution of select():
      java.io.IOException: An operation was attempted on something that is not a socket

      at java.base/sun.nio.ch.WindowsSelectorImpl$FinishLock.checkForException(WindowsSelectorImpl.java:328)
      at java.base/sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:189)
      at java.base/sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:129)
      at java.base/sun.nio.ch.SelectorImpl.select(SelectorImpl.java:141)
      at java.net.http/jdk.internal.net.http.HttpClientImpl$SelectorManager.run(HttpClientImpl.java:870)

      <debug> [HttpClient-1-SelectorManager] [717ms] HttpClientImpl(1) SelectorManager shutting down
      <debug> [AWT-EventQueue-0] [717ms] ExchangeImpl get: Trying to get HTTP/2 connection
      <debug> [HttpClient-1-SelectorManager] [718ms] Http2ClientImpl stopping

      ---------- BEGIN SOURCE ----------
      import java.net.URI;
      import java.net.http.HttpClient;
      import java.net.http.HttpRequest;
      import java.net.http.HttpResponse;
      import java.time.Duration;
      import java.util.LinkedHashMap;
      import java.util.Map;
       
      public class HttpClientGet {
           
          private final static Duration CONNECTION_TIMEOUT = Duration.ofSeconds(5);
          private final static Duration REST_TIMEOUT = Duration.ofSeconds(30);
          private final static String REST_URL = "http://calapi.inadiutorium.cz/api/v0/en/calendars/general-en/today";
           
          public static void main(String[] args) {
              HttpClientGet.executeRest();
          }
           
          private static Map<String, String> getHeaders() {
              final Map<String, String> requestHeader = new LinkedHashMap<>();
              requestHeader.put("Content-Type", "application/x-www-form-urlencoded");
              requestHeader.put("Cache-Control", "no-cache");
              return requestHeader;
          }
           
          private static HttpRequest generateGET(final Map<String, String> header, final String url) {
              final HttpRequest.Builder builder = HttpRequest.newBuilder();
              builder.uri(URI.create(url));
              builder.timeout(REST_TIMEOUT);
              for(final String headerKey: header.keySet()) {
                  builder.header(headerKey, header.get(headerKey));
              }
              builder.GET();
              return builder.build();
          }
           
          private static void executeRest() {
              HttpClient httpClient = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).connectTimeout(CONNECTION_TIMEOUT).build();
              HttpResponse<String> response = null;
              HttpRequest request = HttpClientGet.generateGET(HttpClientGet.getHeaders(), REST_URL);
              try {
                  response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
                  final String responseBody = response.body();
                  System.out.println("Response body: " + responseBody);
              }
              catch(Exception e) {
                  System.err.println("REST Error: " + e.getMessage());
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Uninstall Astrilll VPN

      FREQUENCY : always


            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: