Name: nt126004 Date: 09/30/2002
FULL PRODUCT VERSION :
java version "1.4.1-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b19)
Java HotSpot(TM) Client VM (build 1.4.1-rc-b19, mixed mode)
FULL OPERATING SYSTEM VERSION :
Microsoft Windows 2000 [Version 5.00.2195]
Win2K - Build 2195 - SP3
A DESCRIPTION OF THE PROBLEM :
It seems that the behavior of OP_WRITE has changed in
1.4.1 (bug 4469394). When I register a socket with OP_WRITE,
selector.select() appears to generate a new isWritable key
each time it's called. This ends up blocking all other keys
(I can't get an isReadable key). If I don't register
OP_WRITE, reading works correctly. This is almost exactly the
same as bug 4748181, but that bug was closed as the
correct behavior. Since an isReadable key is never selected,
I think this behavior is incorrect.
REGRESSION. Last worked in version 1.4
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the enclosed source code in DOS box.
2. From DOS, run "telnet localhost 10064"
3. The source will issue of unending "write at **ticks**"
4. run the code with java nio_test reset to unregister OP_WRITE
EXPECTED VERSUS ACTUAL BEHAVIOR :
I would expect that I get one isWritable keys until I
actually write something.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.nio.channels.*;
import java.net.*;
import java.util.*;
public class nio_test
{
public static void main(String[] args) throws Exception
{
System.out.println("Java Version: " + System.getProperty
("java.vm.version", "???"));
boolean reset = (args.length > 0);
Selector selector = Selector.open();
ServerSocketChannel server = ServerSocketChannel.open();
server.configureBlocking(false);
InetSocketAddress address = new InetSocketAddress(10064);
server.socket().bind(address);
server.register(selector, SelectionKey.OP_ACCEPT);
SocketChannel socket = null;
for(;;)
{
if ( selector.select() > 0 )
{
Set keys = selector.selectedKeys();
Iterator iterator = keys.iterator();
while ( iterator.hasNext() )
{
SelectionKey key = (SelectionKey)iterator.next();
iterator.remove();
if ( key.isAcceptable() )
{
System.out.println("accept at " + System.currentTimeMillis());
socket = server.accept();
socket.configureBlocking(false);
socket.socket().setTcpNoDelay(false);
socket.register(selector, SelectionKey.OP_READ | SelectionKey.OP_WRITE);
}
else
{
if ( key.isWritable() )
{
System.out.println("write at " + System.currentTimeMillis());
if (socket != null && reset) {
socket.register(selector, SelectionKey.OP_READ);
}
}
else if ( key.isReadable() )
{
System.out.println("read at " + System.currentTimeMillis());
}
}
}
}
}
}
}
---------- END SOURCE ----------
CUSTOMER WORKAROUND :
Don't use OP_WRITE
(Review ID: 163452)
======================================================================