-
Bug
-
Resolution: Fixed
-
P3
-
7, 7u4
-
b45
-
x86
-
linux_ubuntu, os_x
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2225636 | 7u6 | Andrew Brygin | P3 | Closed | Fixed | b17 |
FULL PRODUCT VERSION :
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.3
EXTRA RELEVANT SYSTEM CONFIGURATION :
Single threaded command line app. Nothing special.
A DESCRIPTION OF THE PROBLEM :
On JDK 1.7, repeated usage of ImageIO.read(ImageInputStream) results in “Too many open files” exception.
Also of interest is the process contains about 10,000 POSIX Semaphores at the same time.
Attempting to close the ImageInputStream manually throws an exception that it is already closed.
JDK 1.6.0_31 does not have this issue.
More details: http://stackoverflow.com/q/10441276/43217
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Repeatedly reading images via ImageIO.read(ImageInputStream) will result in exhaustion of the process's available open file descriptors.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JavaDocs state that ImageIO.read(ImageInputStream) closes input stream unless null is returned:
http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read(javax.imageio.stream.ImageInputStream)
ACTUAL -
FileNotFoundException: "Too many open files"
Over 10,000 POSIX Semaphores in the process:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
...
java 36809 smm *235r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *236r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *237r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *238r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *239r PSXSEM 0t0 kcms00008FC901624000
ERROR MESSAGES/STACK TRACES THAT OCCUR :
FileNotFoundException: "Too many open files"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// Repeatedly executing this code produces it for me.
BufferedImage image = null;
ImageInputStream stream = null;
try {
stream = new FileImageInputStream(file);
image = ImageIO.read(stream);
} catch (Exception ex) {
log.error("Image could not be read: "+file.getPath());
} finally {
// ImageIO closes input stream unless null is returned
// http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read(javax.imageio.stream.ImageInputStream)
if (stream != null && image == null) {
try {
stream.close();
} catch (IOException ex) {
log.error("ERROR closing image input stream: "+ex.getMessage(), ex);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
// I expected the results to be the same as executing this code (which works fine):
BufferedImage image = null;
InputStream stream = null;
try {
stream = new FileInputStream(file);
image = ImageIO.read(stream);
} catch (Exception ex) {
log.error("Image could not be read: "+file);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ex) {
log.error("ERROR closing image input stream: "+ex.getMessage(), ex);
}
}
}
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.3
EXTRA RELEVANT SYSTEM CONFIGURATION :
Single threaded command line app. Nothing special.
A DESCRIPTION OF THE PROBLEM :
On JDK 1.7, repeated usage of ImageIO.read(ImageInputStream) results in “Too many open files” exception.
Also of interest is the process contains about 10,000 POSIX Semaphores at the same time.
Attempting to close the ImageInputStream manually throws an exception that it is already closed.
JDK 1.6.0_31 does not have this issue.
More details: http://stackoverflow.com/q/10441276/43217
REGRESSION. Last worked in version 6u31
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Repeatedly reading images via ImageIO.read(ImageInputStream) will result in exhaustion of the process's available open file descriptors.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JavaDocs state that ImageIO.read(ImageInputStream) closes input stream unless null is returned:
http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read(javax.imageio.stream.ImageInputStream)
ACTUAL -
FileNotFoundException: "Too many open files"
Over 10,000 POSIX Semaphores in the process:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
...
java 36809 smm *235r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *236r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *237r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *238r PSXSEM 0t0 kcms00008FC901624000
java 36809 smm *239r PSXSEM 0t0 kcms00008FC901624000
ERROR MESSAGES/STACK TRACES THAT OCCUR :
FileNotFoundException: "Too many open files"
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
// Repeatedly executing this code produces it for me.
BufferedImage image = null;
ImageInputStream stream = null;
try {
stream = new FileImageInputStream(file);
image = ImageIO.read(stream);
} catch (Exception ex) {
log.error("Image could not be read: "+file.getPath());
} finally {
// ImageIO closes input stream unless null is returned
// http://docs.oracle.com/javase/7/docs/api/javax/imageio/ImageIO.html#read(javax.imageio.stream.ImageInputStream)
if (stream != null && image == null) {
try {
stream.close();
} catch (IOException ex) {
log.error("ERROR closing image input stream: "+ex.getMessage(), ex);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
// I expected the results to be the same as executing this code (which works fine):
BufferedImage image = null;
InputStream stream = null;
try {
stream = new FileInputStream(file);
image = ImageIO.read(stream);
} catch (Exception ex) {
log.error("Image could not be read: "+file);
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException ex) {
log.error("ERROR closing image input stream: "+ex.getMessage(), ex);
}
}
}
- backported by
-
JDK-2225636 javax.imageio.ImageIO.read(ImageInputStream) leaks file handlers
-
- Closed
-
- duplicates
-
JDK-7167647 [macosx] Posix semaphore leak in ColorSpace
-
- Closed
-
-
JDK-7170971 ImageIO leaks mmaps in jdk1.7.0_04 with certain JPEGs on linux.
-
- Closed
-
- relates to
-
JDK-8214503 ImageIO.read(url) does not close TCP connections when the url does not exist
-
- Closed
-