JDK-8214503 : 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: 7u80,8,11,12
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2018-11-29
  • Updated: 2020-05-28
  • Resolved: 2019-01-16
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
tbdResolved
Related Reports
Relates :  
Relates :  
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



Comments
Not seeing increase in TCP close_wait state when ran test for 20 mins in Win 7 and Mac )S 10.13 environments. Used JDK8 and latest JDk development branch code. In between there might be 1 or 2 Close_Wait status but they are not seen when i run "netstat -an" again.
16-01-2019

Reported with JDK 7u80, executing ImageIO.read(url) when the resource of url does not exist, keep increasing number of "TCP close_wait". Written back to the submitter requesting additional information including status with current JDK version 8u191 and 12 ea build. Submitter responded back with the test case (attached in subsequent comment), confirming that the issue does reproduce with JDK 8u191 and 12 ea b22. Exact steps to reproduce: - Compile and run attached test case (Linux or Windows) - Watch out tcp staus���you will see a large number of TCP "CLOSE_WAIT".(no matter linux or Windows) See attached screenshot as reference. These exceptions (FileNotFoundException,Can't get input stream from URL) can be ignored, and real user access allows for scenarios like this. The key problem is ImageIO.read(url) doesn't handle connections properly! Causes the number of TCP "CLOSE_WAIT" to increase consistently. Related issue: JDK-7166379
30-11-2018

Reported with JDK 7u80, executing ImageIO.read(url) when the resource of url does not exist, keep increasing number of "TCP close_wait". Written back to the submitter requesting additional information with complete test case and status with current JDK version 8u191 and 12 ea build.
30-11-2018