Hi Trustin,<div>On further testing - Ive discovered that the future is actually capturing the exception in event of failure. I&#39;d made the assumption that channelFuture.await() would return false when an error condition was found. Checking channelFuture.getCause() != null lets me determine failure.</div>
<div><br></div><div>Cheers, Neil.<br><br><div class="gmail_quote">On Mon, Jun 7, 2010 at 9:58 AM, Neil Avery <span dir="ltr">&lt;<a href="mailto:neil@liquidlabs.co.uk">neil@liquidlabs.co.uk</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi Trustin,<div>My bad - I meant to say the channelFuture.await() returns true.</div><div><br></div><div><div>        <span style="white-space:pre">        </span>channelFuture = bootstrap.connect(remoteAddress, null);</div>
<div>        <span style="white-space:pre">        </span>boolean success = channelFuture.await(connectionEstablishTimeoutSecs, TimeUnit.SECONDS);</div><div><br></div><div>Ill try and sort out a simple testcase.</div>
<div>Cheers Neil.</div><div><div></div><div class="h5"><div><br></div><br><div class="gmail_quote">On Mon, Jun 7, 2010 at 3:49 AM, &quot;Trustin Lee (이희승)&quot; <span dir="ltr">&lt;<a href="mailto:trustin@gmail.com" target="_blank">trustin@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Neil,<br>
<br>
ClientBootstrap.connect() does not return a boolean but returns a<br>
ChannelFuture.  What property values does the returned ChannelFuture have?<br>
<br>
The stack trace you pasted tells me that the exception was not triggered<br>
by write().  If you wrote something and it triggered the exception,<br>
NioWorker should show up in the trace instead of<br>
NioClientSocketPipelineSink.<br>
<br>
To make sure if this really is a Netty issue, could you please post a<br>
very simple application that reproduces the problem?<br>
<br>
Thanks in advance,<br>
Trustin<br>
<div><div></div><div><br>
Neil Avery wrote:<br>
&gt; Hi all,<br>
&gt; Ive been given a requirement to make client ports run in a particular<br>
&gt; range. Being the client side, it looks like java client sockets dont<br>
&gt; support the SO_ADDR_REUSE in that client-sockets in TIMED_WAIT cannot be<br>
&gt; bound to - they blow up with &#39;Address already in use&#39;.<br>
&gt;<br>
&gt; To overcome this problem, Ive had to resort to determining availability<br>
&gt; by establishing a client socket connection to a server socket - not<br>
&gt; pretty - but using a ServerSocket() with addressResult(false) doesn&#39;t<br>
&gt; work - its like the flag is ignored and allows those ports to be reused.<br>
&gt; BTW - Im using jdk sockets for the checking process.<br>
&gt;<br>
&gt; The problem Ive encountered is when a race-state occurs and many client<br>
&gt; socket connections start at the same time, it seems that the<br>
&gt; bootstrap.connect(serverSocket,clientSocket) - is returning &#39;true&#39;<br>
&gt; indicating a connect success, however it turns out that the connection<br>
&gt; is not completed so when the channel is  used and I receive the<br>
&gt; exception below. I would like the ability to know the connection was<br>
&gt; actually successful/bound as a result of the connect future, so its<br>
&gt; possible to take corrective action, rather than at the write state/stage.<br>
&gt;<br>
&gt; java.net.BindException: Address already in use: no further information<br>
&gt; at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)<br>
&gt; at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:574)<br>
&gt; at<br>
&gt; org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:384)<br>
&gt; at<br>
&gt; org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:354)<br>
&gt; at<br>
&gt; org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:276)<br>
&gt; at<br>
&gt; org.jboss.netty.util.internal.IoWorkerRunnable.run(IoWorkerRunnable.java:46)<br>
&gt; at<br>
&gt; java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)<br>
&gt; at<br>
&gt; java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)<br>
&gt; at java.lang.Thread.run(Thread.java:619)<br>
&gt;<br>
&gt; Its fairly eay to reproduce.... use netty to establish a client socket<br>
&gt; connection on a port in a timed_wait state, and it will report<br>
&gt; bootstrap.connect(remote,local) == true. Then when writing to the socket<br>
&gt; it will fail with the above exception.<br>
&gt;<br>
&gt;<br>
&gt; Regards Neil.<br>
&gt;<br>
&gt; --<br>
&gt;<br>
</div></div>&gt; <a href="http://www.liquidlabs.co.uk" target="_blank">www.liquidlabs.co.uk</a> &lt;<a href="http://www.liquidlabs.co.uk" target="_blank">http://www.liquidlabs.co.uk</a>&gt;<br>
&gt;<br>
&gt;<br>
&gt; ------------------------------------------------------------------------<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; netty-users mailing list<br>
&gt; <a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
<font color="#888888"><br>
--<br>
what we call human nature in actuality is human habit<br>
<a href="http://gleamynode.net/" target="_blank">http://gleamynode.net/</a><br>
<br>
_______________________________________________<br>
netty-users mailing list<br>
<a href="mailto:netty-users@lists.jboss.org" target="_blank">netty-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/netty-users" target="_blank">https://lists.jboss.org/mailman/listinfo/netty-users</a><br>
</font></blockquote></div><br><br clear="all"><br></div></div>-- <br><br><a href="http://www.liquidlabs.co.uk" target="_blank">www.liquidlabs.co.uk</a><br>
</div>
</blockquote></div><br><br clear="all"><br>-- <br><br><a href="http://www.liquidlabs.co.uk">www.liquidlabs.co.uk</a><br>
</div>