JDK-4516760 : (so) Intermittent SocketException: Transport endpoint is not connected (lnx)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0,6
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2001-10-19
  • Updated: 2009-08-14
  • Resolved: 2009-08-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b70Fixed
Description
A test making connections to various web servers from Linux intermittently
fails with:

Test caughtjava.net.SocketException: Transport endpoint is not connected
java.net.SocketException: Transport endpoint is not connected
        at sun.nio.ch.SocketChannelImpl.shutdown(Native Method)
        at sun.nio.ch.SocketChannelImpl.shutdownInput(SocketChannelImpl.java:362)
        at sun.nio.ch.SocketAdaptor.shutdownInput(SocketAdaptor.java:344)
        at webClientTest2.<init>(webClientTest2.java:132)
        at webClientTest2.main(webClientTest2.java:244)


Execute the attached test, webClientTest2 in either blocking (use -b) 
or non-blocking mode (default) to any webserver. Examples:

java webClientTest2 -webServer impulse.sfbay.sun.com  
java webClientTest2 -webServer impulse.sfbay.sun.com -b
java webClientTest2 -webServer 129.145.129.119 -port 80 
java webClientTest2 -webServer 129.145.129.119 -port 80 -b

Comments
EVALUATION The intermittent exception stems from a timing issue whereby the shutdownOutput can be called before or after the connection has been closed by the http server. If the connection has been closed then Linux's shutdown(2) returns ENOTCONN leading to the observed exception. The equivalent shutdown(3SOCKET) on Solaris does not fail if the connection has been closed by the peer. It's not clear that the Linux behaviour is correct because ENOTCONN is more typically returned if no connection has been established - in this case the socket was connected but the peer has now closed the connection. Either way the specification for Socket.shutdown{Input,Output} doesn't yet specify the required behaviour if the peer has closed the connection (this should be fixed post-merlin). Additionally, the reason a similiar failure isn't observed with java.net.Socket is because the default SocketImpl doesn't check the return code from shutdown and doesn't observe the error. As regards this bug - the right solution is probably for SocketChannel.socket().shutdown{Input,Output} to do a isConnected() check to ensure a connection was established and additionally ignore the ENOTCONN error on Linux so that the behaviour is the same as the other platforms. ###@###.### 2002-01-02
02-01-2002