Mytec
Be careful with SelectionKey interests! :)
I spent one day catching the bug in the client side implementation of Grizzly 2.0
The code bellow:
selector.select();Set<SelectionKey> readyKeySet = selector.selectedKeys();
for(Iterator<SelectionKey> it = readyKeySet.iterator(); it.hasNext(); ) {
SelectionKey key = it.next();
....................
is usual way of processing I/O events with Java NIO.
The SelectionKey should now tell us, which operation is ready to be processed, but
int readyOperations = key.readyOps();
returns 0 8-)
This is really unexpected, because it means, that SelectionKey is not ready for any I/O operation, and even more...
selector.select() now returns immediately all the time with non-ready SelectionKey. So our Selector thread is loading CPU up-to 100%.
After one day of investigation and trying different patches I realized, that issue occurred, because I forgot to unregister OP_CONNECT interest from the SelectionKey. Once I added logic to unregister OP_CONNECT interest, when a channel gets connected - everything started to work just fine.
I saw such an issue just on my Mac, so not sure how other OS'es JVM will behave. Anyway if you don't want to spend the day catching strange NIO bugs - be careful with SelectionKey interests :)
Posted at 11:06AM Sep 24, 2008 by oleksiys in Grizzly | Comments[0]