-
Bug
-
Resolution: Fixed
-
P2
-
6
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2164021 | 6u10 | Alan Bateman | P4 | Closed | Fixed | b31 |
JDK-2164022 | OpenJDK6 | Alan Bateman | P4 | Resolved | Fixed | b11 |
FULL PRODUCT VERSION :
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux hostname 2.6.17-11-386 #2 Fri May 18 23:37:00 UTC 2007 i686 GNU/Linux
Ubuntu 6.10
A DESCRIPTION OF THE PROBLEM :
I have implemented a timeout for the thread blocking on the I/O operation using InterruptableChannel interface. It works just fine with jdk 1.5.0_10. The ClosedByInterruptException is thrown and caught (please see the sample code below)
However, on Java 6 it seems like the the blocked thread never receives the ClosedByInterruptException.
If the read is attempeted after the interrupt then the ClosedChannelException is thrown and the thread is stopped. However if no read happens the thread blocks for ever.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code provided below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Start
user input
Read line:'user input'
INTERRUPTING
LEAVING java.nio.channels.ClosedByInterruptException
ACTUAL -
Start
user input 1
Read line:'user input 1'
INTERRUPTING
However if I try yet another "user input" AFTER the interrupt, I get:
Start
user input
Read line:'user input'
INTERRUPTING
user input 2
Read line:'user input 2'
LEAVING java.nio.channels.ClosedChannelException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.channels.Channels;
public class InterruptInput {
public static void main(String args[]) {
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(
Channels.newInputStream(
(new FileInputStream(FileDescriptor.in)).getChannel())));
System.out.println("Start");
// interrupt input in 10 sec
(new TimeOut()).start();
String line = null;
while ((line = in.readLine()) != null) {
System.out.println("Read line:'"+line+"'");
}
} catch (Exception ex) {
System.out.println("LEAVING " + ex.toString());
}
}
public static class TimeOut extends Thread {
Thread threadToInterrupt = null;
public TimeOut() {
// interrupt thread that creates this TimeOut.
threadToInterrupt = Thread.currentThread();
setDaemon(true);
}
public void run() {
try {
sleep(10000);
} catch(InterruptedException ex) {/*ignore*/}
System.out.println("INTERRUPTING");
threadToInterrupt.interrupt();
}
}
}
---------- END SOURCE ----------
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) Client VM (build 1.6.0_02-b05, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux hostname 2.6.17-11-386 #2 Fri May 18 23:37:00 UTC 2007 i686 GNU/Linux
Ubuntu 6.10
A DESCRIPTION OF THE PROBLEM :
I have implemented a timeout for the thread blocking on the I/O operation using InterruptableChannel interface. It works just fine with jdk 1.5.0_10. The ClosedByInterruptException is thrown and caught (please see the sample code below)
However, on Java 6 it seems like the the blocked thread never receives the ClosedByInterruptException.
If the read is attempeted after the interrupt then the ClosedChannelException is thrown and the thread is stopped. However if no read happens the thread blocks for ever.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the code provided below.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Start
user input
Read line:'user input'
INTERRUPTING
LEAVING java.nio.channels.ClosedByInterruptException
ACTUAL -
Start
user input 1
Read line:'user input 1'
INTERRUPTING
However if I try yet another "user input" AFTER the interrupt, I get:
Start
user input
Read line:'user input'
INTERRUPTING
user input 2
Read line:'user input 2'
LEAVING java.nio.channels.ClosedChannelException
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.BufferedReader;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.channels.Channels;
public class InterruptInput {
public static void main(String args[]) {
try {
BufferedReader in = new BufferedReader(
new InputStreamReader(
Channels.newInputStream(
(new FileInputStream(FileDescriptor.in)).getChannel())));
System.out.println("Start");
// interrupt input in 10 sec
(new TimeOut()).start();
String line = null;
while ((line = in.readLine()) != null) {
System.out.println("Read line:'"+line+"'");
}
} catch (Exception ex) {
System.out.println("LEAVING " + ex.toString());
}
}
public static class TimeOut extends Thread {
Thread threadToInterrupt = null;
public TimeOut() {
// interrupt thread that creates this TimeOut.
threadToInterrupt = Thread.currentThread();
setDaemon(true);
}
public void run() {
try {
sleep(10000);
} catch(InterruptedException ex) {/*ignore*/}
System.out.println("INTERRUPTING");
threadToInterrupt.interrupt();
}
}
}
---------- END SOURCE ----------
Release Regression From : 5.0
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
- backported by
-
JDK-2164022 (fc) ClosedByInterruptException not thrown by the interrupt method (lnx)
- Resolved
-
JDK-2164021 (fc) ClosedByInterruptException not thrown by the interrupt method (lnx)
- Closed
- relates to
-
JDK-6285901 (so) Data corruption with asynchronous close (Solaris/Linux)
- Resolved