United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 4960962 (so) SocketChannel.close() does not close immediately when channel is registered
4960962 : (so) SocketChannel.close() does not close immediately when channel is registered

Details
Type:
Bug
Submit Date:
2003-11-28
Status:
Resolved
Updated Date:
2005-04-16
Project Name:
JDK
Resolved Date:
2005-04-16
Component:
core-libs
OS:
generic
Sub-Component:
java.nio
CPU:
unknown
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
6

Related Reports
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

Description
SocketChannel.close() is not closing the underlying
socket when the channel is non blocking and registered with a 
Selector. [See comments for simple test case]

The problem seems to be in the socket pre/post close logic
and there are actually a couple of bugs I believe.

1. On Unix the dummy version of NativeDispatcher.preClose()
   is being called instead of the one in FileDispatcher. This
   is because SocketDispatcher extends NativeDispatcher instead
   of FileDispatcher. So, if you make SocketDispatcher extend
   FileDispatcher, this fixes the problem on Unix.

2. The problem also happens on Windows, presumably because the
   actual socket close should be happening (but is not) in the preClose()
   function.

Strangely, this seems to be a long standing issue. I can reproduce with
every release back to 1.4.0.

                                    

Comments
EVALUATION

This is definitely a bug.  Its effect is ameliorated by the fact that a closed
registered socket will be truly closed once it's been completely deregistered.
In a busy application that's managing many connections it's therefore unlikely
that the delay between an invocation of a socket channel's close method and the
actual closing of the underlying socket will be very long.  This might explain
why this bug has not yet been reported.

The submitter's analysis and suggested fix for the Unix implementation appear
to be correct.  The fix for the Windows implementation requires further
investigation; closing the socket in preClose method could bollix up the
Windows selector logic.

-- ###@###.### 2003/11/30
                                     
196-11-11 0



Hardware and Software, Engineered to Work Together