United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4516760 (so) Intermittent SocketException: Transport endpoint is not connected (lnx)
JDK-4516760 : (so) Intermittent SocketException: Transport endpoint is not connected (lnx)

Details
Type:
Bug
Submit Date:
2001-10-19
Status:
Resolved
Updated Date:
2009-08-14
Project Name:
JDK
Resolved Date:
2009-08-14
Component:
core-libs
OS:
generic
Sub-Component:
java.nio
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.0,6
Fixed Versions:

Related Reports

Sub Tasks

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
                                     
2002-01-02



Hardware and Software, Engineered to Work Together