JDK-8246041 : ImageIO.read(url) does not close TCP connections when the url does not exist
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 8,9,11,14,15
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2020-05-25
  • Updated: 2020-11-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Linux CentOS

A DESCRIPTION OF THE PROBLEM :
When the URL cannot be accessed, the bufferedimage read method directly throws an exception and does not execute into finally istream.close ()

Related bugs are https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8214503

REGRESSION : Last worked in version 8u251

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The TestCode is:
package com.vivo.controller;

import org.junit.Test;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.URL;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class TestReadFile {

    @Test
    public void testRead() throws InterruptedException {
        ExecutorService ex = Executors.newFixedThreadPool(100);
        for (int i = 0; i < 1000; i++) {
            ex.execute(task());
        }
        Thread.sleep(100000);
    }

    /**
     */
    private static Runnable task() {
        return new Runnable() {
            @Override
            public void run() {
                // domain must exists,but file doesnot.
                String vivofsUrl = "https://vivobbs.xx.yy.zz/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) {
                    e.printStackTrace();
                } finally {
                    if (null != file) {
                        file.delete();
                    }
                    if (null != image) {
                        image.flush();
                        image = null;
                    }

                }
            }
        };
    }

}


FREQUENCY : always



Comments
[~jdv] I am running "netstat -an" command to check tcp status.
09-06-2020

[~sswsharm] I am able to see the IIOException. But i am not able to capture information related to TCP status? What measures are u taking to actually see TCP status issue?
09-06-2020

The bufferedimage read method directly throws "javax.imageio.IIOException: Can't get input stream from URL! " When checked TCP status, close_wait was not observed. OS:Linux JDK8u251 Fail JDK 9 Fail JDK 14.1 Fail
28-05-2020