Vertx HTTP client connection was closed exception

1,696 views
Skip to first unread message

Idan Fridman

unread,
Nov 23, 2015, 11:57:32 AM11/23/15
to vert.x
I am trying to understand if I am using Vertx HTTP client properly. 
I am doing HTTP post requests and I get times to times "Connection was closed" and sometimes the requests not realy dispatched (without an exception):

015-11-23 16:30:34,917 ERROR [com.company.push.core.verticles.PushMessageVerticle] - <error send push to parse>
io.vertx.core.VertxException: Connection was closed
at io.vertx.core.http.impl.ClientConnection.handleClosed(ClientConnection.java:305)
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$16(ContextImpl.java:333)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:225)
at io.vertx.core.net.impl.VertxHandler.channelInactive(VertxHandler.java:99)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelInactive(AbstractChannelHandlerContext.java:208)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelInactive(AbstractChannelHandlerContext.java:194)
at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:306)
at io.netty.handler.codec.http.HttpClientCodec$Decoder.channelInactive(HttpClientCodec.java:212)



my code:

public class MyVerticle extends AbstractVerticle {



private static final int CONNS = 10000;

public void start() throws RuntimeException {

HttpClientOptions options = new HttpClientOptions().setSsl(true).
setTrustAll(true).setDefaultPort(443).
setKeepAlive(true).setMaxPoolSize(CONNS);
HttpClient client = vertx.createHttpClient(options);

vertx.eventBus().consumer(Constants.PUSH_MESSAGE_DEST_ADDRESS, (handler) -> {
{
String pushNotificationInJson = handler.body().toString();

HttpClientRequest request = client.request(HttpMethod.POST, "dest-url", "uri-params", response -> {
response.bodyHandler(b -> log.debug("response=" + b));
}).
putHeader("someHeaderKey", someHeadyVal).
putHeader("Content-Type", "application/json");

request.exceptionHandler(h -> {
client.close();
log.error("error send push", h);
});
request.setChunked(true);
request.write(pushNotificationInJson);
request.end();
}
});
}

Any idea if I am doing something wrong ?
thank you.

Nat

unread,
Nov 23, 2015, 12:25:35 PM11/23/15
to vert.x
I think 
- your error is masked by client.close() you put in to exceptionHandler. You can probably remove that
- if you don't specify host/port in httpclientoptions, request() without host/port arguments would connect to localhost:80 by default. If you want to connect to a specific url with host/port information, you should probably use requestAbs() instead.

Idan Fridman

unread,
Nov 24, 2015, 3:51:50 AM11/24/15
to vert.x
Thanks for your response.
I am taking the client.close() off but it still doesnt explain why it closing all connections? I have connections-pool dont i?

thanks.

Idan Fridman

unread,
Nov 24, 2015, 3:55:19 AM11/24/15
to vert.x
if you don't specify host/port in httpclientoptions

I did specify port (443) but not host. but it still worked 
 



On Monday, November 23, 2015 at 7:25:35 PM UTC+2, Nat wrote:
Reply all
Reply to author
Forward
0 new messages