-
Bug
-
Resolution: Unresolved
-
P3
-
7, 8
-
Cause Known
-
x86
-
windows_7
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7: Microsoft Windows [Version 6.1.7600]
A DESCRIPTION OF THE PROBLEM :
Closing an AsynchronousSocketChannel and AsynchronousChannelGroup while there's a pending asynchronous operation results in an uncatchable ShutdownChannelGroupException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Run Server.java
2) Run Client.java
The issue is with the client
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Caught Exception 1: java.nio.channels.AsynchrounousCloseException
This is the result in the linux build
ACTUAL -
An exception thrown by a daemon controlled by the nio framework. This exception cannot be caught by the user.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "Thread-0" java.nio.channels.ShutdownChannelGroupException
at sun.nio.ch.Invoker.invokeIndirectly(Invoker.java:210)
at sun.nio.ch.Invoker.invoke(Invoker.java:176)
at sun.nio.ch.Invoker.invoke(Invoker.java:285)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.failed(WindowsAsynchronousSocketChannelImpl.java:577)
at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:399)
at java.lang.Thread.run(Thread.java:722)
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
-= Server =-
public static void main(String...args) throws IOException {
List<Socket> sockets = new LinkedList<Socket>();
ServerSocket ssocket = new ServerSocket(4321);
try {
while(true)
sockets.add(ssocket.accept());
} finally {
for(Socket s : sockets)
s.close();
ssocket.close();
}
}
-= Client =-
public static void main(String...args) throws IOException, InterruptedException {
// Create AsynchronousChannelGroup
final AsynchronousChannelGroup acg = AsynchronousChannelGroup.withThreadPool(Executors.newCachedThreadPool());
// Create Client AsynchronousSocketChannel
final AsynchronousSocketChannel asc = AsynchronousSocketChannel.open(acg);
// Connect to local server
asc.connect(new InetSocketAddress("localhost" ,4321), null, new CompletionHandler<Void,Void>() {
@Override
public void completed(Void result, Void attachment) {
// The client has connected to the server
try {
// Asynchronous read (the server should not respond)
ByteBuffer buff = ByteBuffer.allocateDirect(1024);
asc.read(buff, buff, new CompletionHandler<Integer, ByteBuffer>() {
@Override
public void completed(Integer result, ByteBuffer attachment) {
// Data has been read into the buffer
// The server should not write to the client
assert false;
}
@Override
public void failed(Throwable exc, ByteBuffer attachment) {
// The read failed.
System.err.println("Caught Exception 1: " + exc);
}
});
// Close the client
asc.close();
// Close the channel group
acg.shutdown();
} catch (Throwable exc) {
System.err.println("Caught Exception 2: " + exc);
}
}
@Override
public void failed(Throwable exc, Void attachment) {
try {
System.err.println("Caught Exception 4: " + exc);
asc.close();
acg.shutdown();
} catch (Throwable exc2) {
System.err.println("Caught Exception 5: " + exc2);
}
}
});
// Pause main thread
synchronized(Client.class) {Client.class.wait(10000);}
}
---------- END SOURCE ----------
Java(TM) SE Runtime Environment (build 1.7.0-ea-b145)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 7: Microsoft Windows [Version 6.1.7600]
A DESCRIPTION OF THE PROBLEM :
Closing an AsynchronousSocketChannel and AsynchronousChannelGroup while there's a pending asynchronous operation results in an uncatchable ShutdownChannelGroupException.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Run Server.java
2) Run Client.java
The issue is with the client
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Caught Exception 1: java.nio.channels.AsynchrounousCloseException
This is the result in the linux build
ACTUAL -
An exception thrown by a daemon controlled by the nio framework. This exception cannot be caught by the user.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "Thread-0" java.nio.channels.ShutdownChannelGroupException
at sun.nio.ch.Invoker.invokeIndirectly(Invoker.java:210)
at sun.nio.ch.Invoker.invoke(Invoker.java:176)
at sun.nio.ch.Invoker.invoke(Invoker.java:285)
at sun.nio.ch.WindowsAsynchronousSocketChannelImpl$ReadTask.failed(WindowsAsynchronousSocketChannelImpl.java:577)
at sun.nio.ch.Iocp$EventHandlerTask.run(Iocp.java:399)
at java.lang.Thread.run(Thread.java:722)
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
-= Server =-
public static void main(String...args) throws IOException {
List<Socket> sockets = new LinkedList<Socket>();
ServerSocket ssocket = new ServerSocket(4321);
try {
while(true)
sockets.add(ssocket.accept());
} finally {
for(Socket s : sockets)
s.close();
ssocket.close();
}
}
-= Client =-
public static void main(String...args) throws IOException, InterruptedException {
// Create AsynchronousChannelGroup
final AsynchronousChannelGroup acg = AsynchronousChannelGroup.withThreadPool(Executors.newCachedThreadPool());
// Create Client AsynchronousSocketChannel
final AsynchronousSocketChannel asc = AsynchronousSocketChannel.open(acg);
// Connect to local server
asc.connect(new InetSocketAddress("localhost" ,4321), null, new CompletionHandler<Void,Void>() {
@Override
public void completed(Void result, Void attachment) {
// The client has connected to the server
try {
// Asynchronous read (the server should not respond)
ByteBuffer buff = ByteBuffer.allocateDirect(1024);
asc.read(buff, buff, new CompletionHandler<Integer, ByteBuffer>() {
@Override
public void completed(Integer result, ByteBuffer attachment) {
// Data has been read into the buffer
// The server should not write to the client
assert false;
}
@Override
public void failed(Throwable exc, ByteBuffer attachment) {
// The read failed.
System.err.println("Caught Exception 1: " + exc);
}
});
// Close the client
asc.close();
// Close the channel group
acg.shutdown();
} catch (Throwable exc) {
System.err.println("Caught Exception 2: " + exc);
}
}
@Override
public void failed(Throwable exc, Void attachment) {
try {
System.err.println("Caught Exception 4: " + exc);
asc.close();
acg.shutdown();
} catch (Throwable exc2) {
System.err.println("Caught Exception 5: " + exc2);
}
}
});
// Pause main thread
synchronized(Client.class) {Client.class.wait(10000);}
}
---------- END SOURCE ----------