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

Java HttpsURLConnection delay 10 to 15 seconds on ARM

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      we have on our environment ARMv7
      Linux kernel 4.9, java 1.8 version using tls 1.2 default
      Also tested on raperry pi3 and beaglesnake target board armv7 same delay. and also on our custom board.

      using curl when we give any https link , it returns within 2 seconds
      using java program using httpsurlconnection class we get 10 seconds or more delay.
      Even removed some ciphers thought it may take sometime but that is not the case.
      Trying an alternative to httpurlconnection class apache httpclient, having issues compiling and running it, any pointers will help.
      Also any pointers or suggestion why we have 10 seconds delay on https connection ?
      I have tested using oracle java 8 also, same result, also tried zulu11 version of java same delay.
      Any suggestions would help


      A DESCRIPTION OF THE PROBLEM :
      Access https link with tls 1.2, see that there is a delay of minimum 10 to 15 seconds to access the link.
      The same link if tried with curl on the same ARM target board, rasperry pi or beaglesnake (ARMv7, 32bit HF) does not cause the delay.

      As understood httpsurlconnection class used to connect to httpslink and retirve the contents causes delay



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the below java program, https link in the java program of google, use any other https server supporting tls 1.2. class generated and run it will be able to see the delay

      Java version 1.8 and higher used.

      compile step

       javac HttpsClient.java


      Run Step

      $ sudo java HttpsClient

      Output ...

      Response Code : 200
      Cipher Suite : TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256


      Cert Type : X.509
      Cert Hash Code : 611626434
      Cert Public Key Algorithm : EC
      Cert Public Key Format : X.509


      Cert Type : X.509
      Cert Hash Code : 1544128074
      Cert Public Key Algorithm : RSA
      Cert Public Key Format : X.509


      ****** Content of the URL ********
      <!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta charset="utf-8"><meta name="google-site-verification" content="ur_4noneF2gwXvKEuAE5xnKunbVtB_pHoC9TZ227s9c"/><title>Google Transparency Report</title><link href="https://fonts.googleapis.com/css?family=Roboto:700,500,400,300|Product+Sans:400" rel="stylesheet"><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"><!-- Add the extended Material icon library --><link href="https://fonts.googleapis.com/icon?family=Material+Icons+Extended" rel="stylesheet"><link rel="shortcut icon" href="https://www.google.com/favicon.ico?v1"><script async="" defer="" src="//www.google.com/insights/consumersurveys/async_survey?site=n5lt72widmih6r4qse43dbf444" nonce="tArXyDyw0q/XR0c8iHAVgw"></script></head><body><app></app><script nonce="tArXyDyw0q/XR0c8iHAVgw">window.google = window.google || {}; window.TR_clientConfig = "\x5bnull,\x22https:\/\/www.gstatic.com\/transparencyreport\/265419707\/assets\/\x22,\x22https:\/\/transparencyreport.google.com\/transparencyreport\/\x22,\x22https:\/\/storage.googleapis.com\/transparencyreport\/\x22,\x5b\x22de\x22,\x22hi\x22,\x22no\x22,\x22ru\x22,\x22fi\x22,\x22bg\x22,\x22fil\x22,\x22lt\x22,\x22hr\x22,\x22lv\x22,\x22pt_BR\x22,\x22fr\x22,\x22hu\x22,\x22es_419\x22,\x22zh_TW\x22,\x22uk\x22,\x22sk\x22,\x22sl\x22,\x22id\x22,\x22ca\x22,\x22sr\x22,\x22sv\x22,\x22ko\x22,\x22el\x22,\x22en\x22,\x22it\x22,\x22es\x22,\x22iw\x22,\x22cs\x22,\x22ar\x22,\x22en_GB\x22,\x22vi\x22,\x22th\x22,\x22ja\x22,\x22zh_CN\x22,\x22fa\x22,\x22pl\x22,\x22da\x22,\x22ro\x22,\x22nl\x22,\x22tr\x22,\x22pt_PT\x22\x5d\n,\x22https:\/\/support.google.com\/transparencyreport\/\x22,null,0\x5d\n";</script><script id="base-js" src="//www.gstatic.com/_/transparencyreport/_/js/k=transparencyreport.tr.en.UqeB42BI3Gg.O/am=5____38F/d=1/rs=ABbJ37UGcIzVtWpa8FoW1OV_pjlMfFYj4Q/m=m" async nonce="tArXyDyw0q/XR0c8iHAVgw"></script><script nonce="tArXyDyw0q/XR0c8iHAVgw">
            window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
            ga('create', 'UA-81678134-1', 'auto');
          </script><script async src="https://www.google-analytics.com/analytics.js" nonce="tArXyDyw0q/XR0c8iHAVgw"></script></body></html>





      Will be able to see the delay

      Source Code below





      ============
      HttpsClient.java
      ========================
      import java.net.MalformedURLException;
      import java.net.URL;
      import java.security.cert.Certificate;
      import java.io.*;

      import javax.net.ssl.HttpsURLConnection;
      import javax.net.ssl.SSLPeerUnverifiedException;

      public class HttpsClient {

         public static void main(String[] args)
         {
              new HttpsClient().testIt();
         }

         private void testIt(){

            //String https_url = "https://www.google.com/";
            String https_url = "https://transparencyreport.google.com/https/overview?hl=en";
            URL url;
            try {

          url = new URL(https_url);
          HttpsURLConnection con = (HttpsURLConnection)url.openConnection();

          //dumpl all cert info
          print_https_cert(con);

          //dump all the content
          print_content(con);

            } catch (MalformedURLException e) {
          e.printStackTrace();
            } catch (IOException e) {
          e.printStackTrace();
            }

         }

         private void print_https_cert(HttpsURLConnection con){
           
          if(con!=null){

            try {

      System.out.println("Response Code : " + con.getResponseCode());
      System.out.println("Cipher Suite : " + con.getCipherSuite());
      System.out.println("\n");

      Certificate[] certs = con.getServerCertificates();
      for(Certificate cert : certs){
        System.out.println("Cert Type : " + cert.getType());
        System.out.println("Cert Hash Code : " + cert.hashCode());
        System.out.println("Cert Public Key Algorithm : "
                                          + cert.getPublicKey().getAlgorithm());
        System.out.println("Cert Public Key Format : "
                                          + cert.getPublicKey().getFormat());
        System.out.println("\n");
      }

      } catch (SSLPeerUnverifiedException e) {
      e.printStackTrace();
      } catch (IOException e){
      e.printStackTrace();
      }

           }

         }

         private void print_content(HttpsURLConnection con){
      if(con!=null){

      try {

        System.out.println("****** Content of the URL ********");
        BufferedReader br =
      new BufferedReader(
      new InputStreamReader(con.getInputStream()));

        String input;

        while ((input = br.readLine()) != null){
           System.out.println(input);
        }
        br.close();

      } catch (IOException e) {
        e.printStackTrace();
      }

             }

         }

      }



      ======================

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should return the content within 1 or 2 max seconds as done on normal Intel Linux Ubuntu machines.

      Run Step ( when run on ARMv7 board)

      $ sudo java HttpsClient
      [sudo] password for somshekar:
      Response Code : 200
      Cipher Suite : TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256


      Cert Type : X.509
      Cert Hash Code : 611626434
      Cert Public Key Algorithm : EC
      Cert Public Key Format : X.509


      Cert Type : X.509
      Cert Hash Code : 1544128074
      Cert Public Key Algorithm : RSA
      Cert Public Key Format : X.509


      ****** Content of the URL ********
      <!DOCTYPE html><html><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta charset="utf-8"><meta name="google-site-verification" content="ur_4noneF2gwXvKEuAE5xnKunbVtB_pHoC9TZ227s9c"/><title>Google Transparency Report</title><link href="https://fonts.googleapis.com/css?family=Roboto:700,500,400,300|Product+Sans:400" rel="stylesheet"><link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"><!-- Add the extended Material icon library --><link href="https://fonts.googleapis.com/icon?family=Material+Icons+Extended" rel="stylesheet"><link rel="shortcut icon" href="https://www.google.com/favicon.ico?v1"><script async="" defer="" src="//www.google.com/insights/consumersurveys/async_survey?site=n5lt72widmih6r4qse43dbf444" nonce="tArXyDyw0q/XR0c8iHAVgw"></script></head><body><app></app><script nonce="tArXyDyw0q/XR0c8iHAVgw">window.google = window.google || {}; window.TR_clientConfig = "\x5bnull,\x22https:\/\/www.gstatic.com\/transparencyreport\/265419707\/assets\/\x22,\x22https:\/\/transparencyreport.google.com\/transparencyreport\/\x22,\x22https:\/\/storage.googleapis.com\/transparencyreport\/\x22,\x5b\x22de\x22,\x22hi\x22,\x22no\x22,\x22ru\x22,\x22fi\x22,\x22bg\x22,\x22fil\x22,\x22lt\x22,\x22hr\x22,\x22lv\x22,\x22pt_BR\x22,\x22fr\x22,\x22hu\x22,\x22es_419\x22,\x22zh_TW\x22,\x22uk\x22,\x22sk\x22,\x22sl\x22,\x22id\x22,\x22ca\x22,\x22sr\x22,\x22sv\x22,\x22ko\x22,\x22el\x22,\x22en\x22,\x22it\x22,\x22es\x22,\x22iw\x22,\x22cs\x22,\x22ar\x22,\x22en_GB\x22,\x22vi\x22,\x22th\x22,\x22ja\x22,\x22zh_CN\x22,\x22fa\x22,\x22pl\x22,\x22da\x22,\x22ro\x22,\x22nl\x22,\x22tr\x22,\x22pt_PT\x22\x5d\n,\x22https:\/\/support.google.com\/transparencyreport\/\x22,null,0\x5d\n";</script><script id="base-js" src="//www.gstatic.com/_/transparencyreport/_/js/k=transparencyreport.tr.en.UqeB42BI3Gg.O/am=5____38F/d=1/rs=ABbJ37UGcIzVtWpa8FoW1OV_pjlMfFYj4Q/m=m" async nonce="tArXyDyw0q/XR0c8iHAVgw"></script><script nonce="tArXyDyw0q/XR0c8iHAVgw">
            window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
            ga('create', 'UA-81678134-1', 'auto');
          </script><script async src="https://www.google-analytics.com/analytics.js" nonce="tArXyDyw0q/XR0c8iHAVgw"></script></body></html>

      ACTUAL -
      Delay of 10 ~15 seconds to reutrn the content

      ---------- BEGIN SOURCE ----------
      HttpsClient.java
      ========================
      import java.net.MalformedURLException;
      import java.net.URL;
      import java.security.cert.Certificate;
      import java.io.*;

      import javax.net.ssl.HttpsURLConnection;
      import javax.net.ssl.SSLPeerUnverifiedException;

      public class HttpsClient {

         public static void main(String[] args)
         {
              new HttpsClient().testIt();
         }

         private void testIt(){

            //String https_url = "https://www.google.com/";
            String https_url = "https://transparencyreport.google.com/https/overview?hl=en";
            URL url;
            try {

          url = new URL(https_url);
          HttpsURLConnection con = (HttpsURLConnection)url.openConnection();

          //dumpl all cert info
          print_https_cert(con);

          //dump all the content
          print_content(con);

            } catch (MalformedURLException e) {
          e.printStackTrace();
            } catch (IOException e) {
          e.printStackTrace();
            }

         }

         private void print_https_cert(HttpsURLConnection con){
           
          if(con!=null){

            try {

      System.out.println("Response Code : " + con.getResponseCode());
      System.out.println("Cipher Suite : " + con.getCipherSuite());
      System.out.println("\n");

      Certificate[] certs = con.getServerCertificates();
      for(Certificate cert : certs){
        System.out.println("Cert Type : " + cert.getType());
        System.out.println("Cert Hash Code : " + cert.hashCode());
        System.out.println("Cert Public Key Algorithm : "
                                          + cert.getPublicKey().getAlgorithm());
        System.out.println("Cert Public Key Format : "
                                          + cert.getPublicKey().getFormat());
        System.out.println("\n");
      }

      } catch (SSLPeerUnverifiedException e) {
      e.printStackTrace();
      } catch (IOException e){
      e.printStackTrace();
      }

           }

         }

         private void print_content(HttpsURLConnection con){
      if(con!=null){

      try {

        System.out.println("****** Content of the URL ********");
        BufferedReader br =
      new BufferedReader(
      new InputStreamReader(con.getInputStream()));

        String input;

        while ((input = br.readLine()) != null){
           System.out.println(input);
        }
        br.close();

      } catch (IOException e) {
        e.printStackTrace();
      }

             }

         }

      }



      ======================
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No Idea, any help will be appreciated,

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              wetmore Bradford Wetmore
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: