JDK-4755720 : registering OP_WRITE in nio 1.4.1 prevents selection of OP_READ events
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2002-09-30
  • Updated: 2002-10-26
  • Resolved: 2002-10-26
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.
Other
1.4.2 mantisFixed
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: mantis FIXED IN: mantis INTEGRATED IN: mantis mantis-b05
14-06-2004

EVALUATION The test case is flawed in that it asks if (key.isWritable()) ... else if (key.isReadable()) which causes OP_WRITE to mask OP_READ. With this flaw the behavior occurs on any platform. Once the flaw is corrected, the real bug is revealed in that the behavior on Solaris is correct but the problem still shows up on Windows. ###@###.### 2002-10-01 This problem is caused by improper integration of the three selector sets on Windows. ###@###.### 2002-10-01
01-10-2002