-
Bug
-
Resolution: Incomplete
-
P4
-
None
-
8u144
-
x86_64
-
linux
FULL PRODUCT VERSION :
java version "1.8.0"
Java(TM) SE Runtime Environment (build pmz3180sr4fp2-20170322_01(SR4 FP2))
IBM J9 VM (build 2.8, JRE 1.8.0 z/OS s390-31 20170314_340265 (JIT enabled, AOT enabled)
J9VM - R28_20170314_2309_B340265
JIT - tr.r14.java.green_20170314_134138
GC - R28_20170314_2309_B340265
J9CL - 20170314_340265)
JCL - 20170318_01 based on Oracle jdk8u121-b13
ADDITIONAL OS VERSION INFORMATION :
z/OS 2.2
Windows 7
A DESCRIPTION OF THE PROBLEM :
If an exception is thrown during the write part of java.nio.file.Files.write() then the file handle is not closed, plus no reference to the handle is returned.
Conditions such as full disk could cause this.
The outcome is:
1. The files are not deleted until they are closed, meaning the disk space cannot be recoverd.
2. With enough of these conditions to occur, the open part starts to fail with Too many open files.
The only way to recover both issues is to restart the JVM.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Append to a file using java.nio.file.Files.write() in a slow loop. Handling the exception (do not end).
Fill up the disk that the file is on.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Disk full exceptions while the disk is full, but never "Too many open files". Since the file handle would be closed each time.
Recovering the disk space would allow the program to resume normal behavior.
ACTUAL -
A number of disk full exceptions, then Too many open files. Depending on OS configuration (e.g. ulimit on Unix).
Recovering the disk space does not resolve the Too many open files condition. The whole program has to be restarted.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.nio.file.FileSystemException: file.txt: EDC5124I Too many open files.
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:104)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:115)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:120)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:227)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:442)
at java.nio.file.Files.newOutputStream(Files.java:184)
at java.nio.file.Files.write(Files.java:3163)
at com.mypackage.myClass(myClass.java:277)
at java.lang.Thread.run(Thread.java:809)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class TestFileWrite {
public TestFileWrite() {
}
public static void main(String[] args) {
while (true) {
try {
String line = "line\n";
Files.write(Paths.get("/tmp/file.txt"), line.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
}
}
}
---------- END SOURCE ----------
java version "1.8.0"
Java(TM) SE Runtime Environment (build pmz3180sr4fp2-20170322_01(SR4 FP2))
IBM J9 VM (build 2.8, JRE 1.8.0 z/OS s390-31 20170314_340265 (JIT enabled, AOT enabled)
J9VM - R28_20170314_2309_B340265
JIT - tr.r14.java.green_20170314_134138
GC - R28_20170314_2309_B340265
J9CL - 20170314_340265)
JCL - 20170318_01 based on Oracle jdk8u121-b13
ADDITIONAL OS VERSION INFORMATION :
z/OS 2.2
Windows 7
A DESCRIPTION OF THE PROBLEM :
If an exception is thrown during the write part of java.nio.file.Files.write() then the file handle is not closed, plus no reference to the handle is returned.
Conditions such as full disk could cause this.
The outcome is:
1. The files are not deleted until they are closed, meaning the disk space cannot be recoverd.
2. With enough of these conditions to occur, the open part starts to fail with Too many open files.
The only way to recover both issues is to restart the JVM.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Append to a file using java.nio.file.Files.write() in a slow loop. Handling the exception (do not end).
Fill up the disk that the file is on.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Disk full exceptions while the disk is full, but never "Too many open files". Since the file handle would be closed each time.
Recovering the disk space would allow the program to resume normal behavior.
ACTUAL -
A number of disk full exceptions, then Too many open files. Depending on OS configuration (e.g. ulimit on Unix).
Recovering the disk space does not resolve the Too many open files condition. The whole program has to be restarted.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.nio.file.FileSystemException: file.txt: EDC5124I Too many open files.
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:104)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:115)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:120)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:227)
at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:442)
at java.nio.file.Files.newOutputStream(Files.java:184)
at java.nio.file.Files.write(Files.java:3163)
at com.mypackage.myClass(myClass.java:277)
at java.lang.Thread.run(Thread.java:809)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
public class TestFileWrite {
public TestFileWrite() {
}
public static void main(String[] args) {
while (true) {
try {
String line = "line\n";
Files.write(Paths.get("/tmp/file.txt"), line.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {}
}
}
}
---------- END SOURCE ----------