Community
Participate
Working Groups
When the remote end of a socket is closed, on the home end of the connection that may either cause a -1 to be returned from SocketChannel.read(ByteBuffer), or it may cause an IOException to be thrown from that call, with the following trace: java.io.IOException: An existing connection was forcibly closed by the remote host at sun.nio.ch.SocketDispatcher.read0(Native Method) at sun.nio.ch.SocketDispatcher.read(Unknown Source) at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) at sun.nio.ch.IOUtil.read(Unknown Source) at sun.nio.ch.SocketChannelImpl.read(Unknown Source)... The former situation (-1) we handle gracefully, while in the latter case we dump the stacktrace. See net4j.buffer.Buffer.java, line 154. It seems there is no clear specification of when the method will exhibit the one or the other behavior; it seems to rather depend on how the process owning the socket was terminated, and whether or not that process ran on a different host or not. See for example: http://www.coderanch.com/t/207367/sockets/java/Detecting-client-disconnection-events As far as I can tell, the -1 and the exception signal the same situation, i.e. remote socket closure. So we should handle both in the same way.
Created attachment 175813 [details] Patch
Created attachment 176082 [details] Patch v2 - ready to be committed Caspar, please clone this bug to maintenance and commit without review. (I've added a minor change in the tests)
Committed to HEAD
Available in R20110608-1407