JDK-4989741 : (so) Selector.select() returns immediately when physical connection broken
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-02-05
  • Updated: 2004-02-11
  • Resolved: 2004-02-11
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 02/05/2004


FULL PRODUCT VERSION :
java version "1.4.2_03"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)

FULL OS VERSION :
Windows XP

A DESCRIPTION OF THE PROBLEM :
If a physical network connection is broken, Selector.select() enters a state where it will always return immediatly with an empty set of selected keys.

This happens without exception if select is monitoring a ServerSocket accepting on "any" interface (other scenarios has not been testet).

For a typical server side application the effect will be a CPU load of 100%.

Reconnecting the physical network does not remedy the situation.

The bug does NOT appear on Linux.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached test program.

Detach the network cable from the computer running the program.


EXPECTED VERSUS ACTUAL BEHAVIOR :
When the program starts up, a single line of text is printed.

A short while after the network is detached, text will begin scrolling, indicating the immediate return of Selector.select()

bash-2.05a$ java -cp . SelectTest
Entering select
Exit from select, return value: 0
Entering select
Exit from select, return value: 0
Entering select
Exit from select, return value: 0
Entering select
Exit from select, return value: 0
Entering select
Exit from select, return value: 0
Entering select
Exit from select, return value: 0
Entering select
Exit from select, return value: 0

and so on..


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.*;
import java.nio.channels.*;


public class SelectTest {
    static final int PORT = 7999;

    public static void main(String[] args) throws Exception {
        ServerSocketChannel channel = ServerSocketChannel.open();
        channel.configureBlocking(false);
        ServerSocket socket = channel.socket();
        
        socket.bind (new InetSocketAddress ((InetAddress)null, PORT));

        Selector selector = Selector.open();
        
        channel.register(selector, SelectionKey.OP_ACCEPT, null);

        while (true) {
            System.out.println("Entering select");
            try {
                int count = selector.select();
                System.out.println("Exit from select, return value: " + count);
            } catch (Throwable ex) {
                ex.printStackTrace();
            }
        }
    }
}

---------- END SOURCE ----------
(Incident Review ID: 182071) 
======================================================================

Comments
EVALUATION Disconnecting the physical connection should make the selector show the channel ready to process but the lack of recovery is a bug that has already been fixed in 1.5 and 1.4.2_05 ###@###.### 2004-02-11
11-02-2004