Message4378

Author amak
Recipients amak, irmen
Date 2009-03-29.15:59:47
SpamBayes Score 6.6280315e-13
Marked as misclassified No
Message-id <1238342389.48.0.483443295643.issue1291@psf.upfronthosting.co.za>
In-reply-to
Content
I was surprised by the MacOS result.

So I took a closer look at the java code I posted, and realised that
there was a glaring omission: the selector's in that server code were
never closed.

So I updated the code to properly close all the selectors: the new
"closing_single_threaded_server.java" is attached.

And the code still reliably reproduces the bug. Except that the reported
exception is different now. The new code reports "Address already in
use: connect"; traceback given below.

In an effort to try and find ways to prevent the bug from happening, I
also added to two options, as follows

1. Cancel keys. Cancelling a SelectionKey removes it from the "interest
set" of a Selector. I added this option to cancel keys to see if it made
any difference to the exception. It didn't.

2. Reselect. In the early days of java.nio, there was some community
advice to do another select on a Selector before closing it, after
cancelling all the keys, to ensure that all SelectionKey cancellation
would have taken effect before a close operation was attempted. (this
was never official advice from Sun however). See the javadocs for more
information about closing selectors.

http://java.sun.com/j2se/1.5.0/docs/api/java/nio/channels/Selector.html

But neither of the options makes any difference. Cancelling the keys
makes no difference. Reselecting makes no difference. The IOException
still occurs in all cases.

As before, I'd be interested to see the behaviour of the
"closing_single_threaded_server" on different platforms.

Here is the new traceback.

Exception in thread "main" java.io.IOException: Unable to establish
loopback connection
        at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:106)
        at java.security.AccessController.doPrivileged(Native Method)
        at sun.nio.ch.PipeImpl.<init>(PipeImpl.java:122)
        at
sun.nio.ch.SelectorProviderImpl.openPipe(SelectorProviderImpl.java:27)
        at java.nio.channels.Pipe.open(Pipe.java:133)
        at
sun.nio.ch.WindowsSelectorImpl.<init>(WindowsSelectorImpl.java:106)
        at
sun.nio.ch.WindowsSelectorProvider.openSelector(WindowsSelectorProvider.java:26)
        at java.nio.channels.Selector.open(Selector.java:209)
        at
closing_single_threaded_server$handler.process(closing_single_threaded_server.java:40)
        at
closing_single_threaded_server.main(closing_single_threaded_server.java:90)
Caused by: java.net.BindException: Address already in use: connect
        at sun.nio.ch.Net.connect(Native Method)
        at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:464)
        at java.nio.channels.SocketChannel.open(SocketChannel.java:146)
        at sun.nio.ch.PipeImpl$Initializer.run(PipeImpl.java:78)
        ... 9 more
History
Date User Action Args
2009-03-29 15:59:49amaksetmessageid: <1238342389.48.0.483443295643.issue1291@psf.upfronthosting.co.za>
2009-03-29 15:59:49amaksetrecipients: + amak, irmen
2009-03-29 15:59:48amaklinkissue1291 messages
2009-03-29 15:59:47amakcreate