How to handle connection timeout exception for HttpClient?

2,888 views
Skip to first unread message

isaiah

unread,
Sep 14, 2012, 8:54:41 AM9/14/12
to ve...@googlegroups.com
FYI, I have a HttpClient to poll a remote service, when a timeout exception occur, the http client crashes, and the requests will pile up. If I catch this exception by specify a exception handler to the http client that closes the http client and create a new one, the old http clients are not gabarge collected some how. How should I handle this?

Unhandled exception
java.net.ConnectException: connection timed out
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processConnectTimeout(NioClientSocketPipelineSink.java:391)
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:289)
        at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
        at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

Pid *

unread,
Sep 14, 2012, 9:43:43 AM9/14/12
to ve...@googlegroups.com

On 14 Sep 2012, at 13:54, isaiah <iss...@gmail.com> wrote:

FYI, I have a HttpClient to poll a remote service, when a timeout exception occur, the http client crashes, and the requests will pile up. If I catch this exception by specify a exception handler to the http client that closes the http client and create a new one, the old http clients are not gabarge collected some how.

If you can write a small test that reproduces this I'll take a look next week.


p


How should I handle this?

Unhandled exception
java.net.ConnectException: connection timed out
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processConnectTimeout(NioClientSocketPipelineSink.java:391)
        at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:289)
        at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)
        at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/vertx/-/4CXBbpRnMJ4J.
To post to this group, send an email to ve...@googlegroups.com.
To unsubscribe from this group, send email to vertx+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/vertx?hl=en-GB.

isaiah

unread,
Sep 14, 2012, 10:31:01 AM9/14/12
to ve...@googlegroups.com
Never mind, this is fixed in master.

   private void failed(NioSocketChannel ch, final Throwable t) {
+    tcpHelper.runOnCorrectThread(ch, new Runnable() {
+      public void run() {
+        pool.connectionClosed();
+      }
+    });

Thanks you all the same.

Segio Campos V.

unread,
Jan 9, 2013, 8:57:47 PM1/9/13
to ve...@googlegroups.com
Hello Isaih. 

In which version it is fixed? I have the same problem in vertx 1.3.0 final.

Thanks.

Issaria Peng

unread,
Jan 10, 2013, 4:05:19 AM1/10/13
to ve...@googlegroups.com
Hi Segio,


It will still print the error message, but the http client won't crash, if you find your requests piled up, set a bigger pool size by HttpClient#setMaxPoolSize.


Hope that helps.

Cheers,
Isaiah P.


--
 
 

Sergio Campos Valdés

unread,
Jan 12, 2013, 11:31:18 AM1/12/13
to ve...@googlegroups.com
Thanks Issaria  Seeing the code i figure out that i was setting up exceptionHandler only in HttpClientRequest but not in the HttpClient. It seems there are two different use cases. On of them for exceptions that happen in target host negotiation time and other in connect resolution time.



2013/1/10 Issaria Peng <iss...@gmail.com>
--
 
 



--
Deseando que Dios le bendiga se despide:

Sergio Andrés Campos Valdés
Ingeniero Informático.
Perfil LinkedIn: http://cl.linkedin.com/in/scamposv
Twitter: chech0x

Reply all
Reply to author
Forward
0 new messages