We are using vertx 3.3.3 and facing intermittent issues with HttpClient. If left idle for sometime the subsequent call fails with a timeout error.
It works as expected if requests are sent continuously.
Sharing the code snippets and exception. The httpClient.postAbs is a vertx webserver and is responsive; the exception thrown in HttpClientRequest is a timeout error, that i am finding it hard to understand. Please let us know your suggestions.
We have created an instance of HttpClient in a verticle's start method
public class ConsumerOffers extends BaseVerticle {
HttpClient httpClient;
public void start() {
HttpClientOptions options = new HttpClientOptions().setMaxPoolSize(5).setIdleTimeout(0).setKeepAlive(true).setTcpKeepAlive(true);
httpClient = vertx.createHttpClient(options);
vertx.eventBus().consumer("offer_get", offersHandler);
}
In the offersHandler, we have the below code
HttpClientRequest request = httpClient.postAbs(url, response -> {
System.out.println("In response ");
});
request.exceptionHandler(e -> {
System.out.println("Received exception: " + e.getMessage());
e.printStackTrace();
});
request.setTimeout(30000);
request.end(httpClientJsonObject.toString());
Exception - printStackTrace
Received exception: The timeout period of 30000ms has been exceeded
java.util.concurrent.TimeoutException: The timeout period of 30000ms has been exceeded
at io.vertx.core.http.impl.HttpClientRequestBase.timeout(HttpClientRequestBase.java:155)
at io.vertx.core.http.impl.HttpClientRequestBase.handleTimeout(HttpClientRequestBase.java:140)
at io.vertx.core.http.impl.HttpClientRequestBase.lambda$setTimeout$0(HttpClientRequestBase.java:100)
at io.vertx.core.http.impl.HttpClientRequestBase$$Lambda$86/2112965167.handle(Unknown Source)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:782)
at io.vertx.core.impl.VertxImpl$InternalTimerHandler.handle(VertxImpl.java:753)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$2(ContextImpl.java:316)
at io.vertx.core.impl.ContextImpl$$Lambda$26/1763344271.run(Unknown Source)
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:440)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Thread.java:745)
Feb 10, 2017 5:44:49 PM io.vertx.core.net.impl.ConnectionBase
SEVERE: java.io.IOException: An existing connection was forcibly closed by the remote host
Received exception: An existing connection was forcibly closed by the remote host
java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288)
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1100)
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:367)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:118)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:610)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:551)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:465)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:437)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873)
at java.lang.Thread.run(Thread.java:745)