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

ImageIO.read(url) does not close TCP connections when the url does not exist

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      JDK : JDK1.7.0_79-b15(bug same in jdk1.7.0_80);
      OS:Windows7 and linux2.6.32


      A DESCRIPTION OF THE PROBLEM :
      1.execute ImageIO.read(url) when the resource of url is not exist.
      2.the number of "TCP close_wait" keeps growing

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1.execute ImageIO.read(url) like the following codes:
       
      //Author:yuyicheng
      // domain must exists,but file doesnot.
      String vivofsUrl = "https://domain/wiwNWYCFW9ieGbWq/20181129/3a2adfde12cd328d81f965088890eeffff.jpg";

      File file = null;

      BufferedImage image = null;

      try {
      file = File.createTempFile("abc", "jpg");

      URL url1 = new URL(vivofsUrl);
      image = ImageIO.read(url1);

      } catch (Throwable e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } finally {
      if (null != file) {
      file.delete();
      }
      if (null != image) {
      image.flush();
      image = null;
      // System.gc();
      }

      }
      2.to execute many times for Obviousness!
      Ofcourse,it will throw FileNotFoundException and "IIOException: Can't get input stream from URL!"),

      3.check tcp status




      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Close Connection correctly.
      ACTUAL -
      1.Tracking TCP flow:many tcp "RST" message occured
      2.print TCP Status:the number of "TCP close_wait" keeps growing

      ---------- BEGIN SOURCE ----------
      public static void main(String[] args) throws InterruptedException {

      ExecutorService ex = Executors.newFixedThreadPool(10);
      for (int i = 0; i < 5000; i++) {
      ex.execute(task());
      }
      }

      /**
      * @throws IOException
      * @throws MalformedURLException
      */
      private static Runnable task() {

      return new Runnable() {

      @Override
      public void run() {
      // Author:yuyicheng
      // domain must exists,but file doesnot.
      String vivofsUrl = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543505646937&di=ec0e29a9994a9a96e044c85228d01d18&imgtype=0&src=http%3A%2F%2Fimages.nike.com%2Fis%2Fimage%2FDotCom%2FPDP_HERO_S%2FNIKE-TEXTURED-FOAM-ROLLER-NER123_644_A.jpg";

      File file = null;

      BufferedImage image = null;

      try {
      file = File.createTempFile("abc", "jpg");

      URL url1 = new URL(vivofsUrl);
      image = ImageIO.read(url1);

      } catch (Throwable e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } finally {
      if (null != file) {
      file.delete();
      }
      if (null != image) {
      image.flush();
      image = null;
      }

      }
      }
      };

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      do not use ImageIO.read(url) ,use others instead!

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jdv Jayathirth D V
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: