Skip to content

Commit

Permalink
Don't mess with the pipeline config
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
  • Loading branch information
tsegismont committed Sep 13, 2016
1 parent bd2ef07 commit 815cce1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 45 deletions.
12 changes: 6 additions & 6 deletions src/main/java/io/vertx/core/http/impl/HttpServerImpl.java
Expand Up @@ -284,7 +284,6 @@ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) thr
pipeline.addLast(new Http1xOrHttp2Handler()); pipeline.addLast(new Http1xOrHttp2Handler());
} }
} }
HttpServerImpl.this.onChannelInitialized(ch);
} }
}); });


Expand Down Expand Up @@ -342,7 +341,10 @@ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) thr
} }


// Visible for testing // Visible for testing
protected void onChannelInitialized(Channel ch) { protected void handleConnectionException(ChannelHandlerContext ctx, Throwable cause) {
Channel channel = ctx.channel();
log.trace("Connection failure", cause);
channel.close();
} }


private VertxHttp2ConnectionHandler<Http2ServerConnection> createHttp2Handler(HandlerHolder<HttpHandler> holder, Channel ch) { private VertxHttp2ConnectionHandler<Http2ServerConnection> createHttp2Handler(HandlerHolder<HttpHandler> holder, Channel ch) {
Expand Down Expand Up @@ -1062,10 +1064,8 @@ private void http1(ChannelHandlerContext ctx, ByteBuf buf) {
} }


@Override @Override
public void exceptionCaught(ChannelHandlerContext chctx, Throwable cause) throws Exception { public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
Channel channel = chctx.channel(); HttpServerImpl.this.handleConnectionException(ctx, cause);
log.trace("Connection failure", cause);
channel.close();
} }
} }
} }
47 changes: 8 additions & 39 deletions src/test/java/io/vertx/test/core/HttpConnectionEarlyResetTest.java
Expand Up @@ -16,9 +16,7 @@


package io.vertx.test.core; package io.vertx.test.core;


import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.vertx.core.http.HttpServer; import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions; import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.impl.HttpServerImpl; import io.vertx.core.http.impl.HttpServerImpl;
Expand All @@ -27,9 +25,12 @@
import io.vertx.core.net.NetSocket; import io.vertx.core.net.NetSocket;
import org.junit.Test; import org.junit.Test;


import java.io.IOException;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;


import static org.hamcrest.CoreMatchers.*;

/** /**
* Make sure that the Netty pipeline has a handler catching the {@link java.io.IOException} if the connection is reset * Make sure that the Netty pipeline has a handler catching the {@link java.io.IOException} if the connection is reset
* before any data has been sent. * before any data has been sent.
Expand All @@ -48,8 +49,10 @@ public void setUp() throws Exception {
CountDownLatch listenLatch = new CountDownLatch(1); CountDownLatch listenLatch = new CountDownLatch(1);
httpServer = new HttpServerImpl((VertxInternal) vertx, new HttpServerOptions()) { httpServer = new HttpServerImpl((VertxInternal) vertx, new HttpServerOptions()) {
@Override @Override
protected void onChannelInitialized(Channel ch) { protected void handleConnectionException(ChannelHandlerContext ctx, Throwable cause) {
ch.pipeline().addFirst(new ResetLatchCountDown()).addLast(new ThrowableRecorder()); super.handleConnectionException(ctx, cause);
caught.set(cause);
resetLatch.countDown();
} }
}.requestHandler(request -> {}).listen(8080, onSuccess(server -> listenLatch.countDown())); }.requestHandler(request -> {}).listen(8080, onSuccess(server -> listenLatch.countDown()));
awaitLatch(listenLatch); awaitLatch(listenLatch);
Expand All @@ -59,7 +62,7 @@ protected void onChannelInitialized(Channel ch) {
public void testExceptionCaught() throws Exception { public void testExceptionCaught() throws Exception {
vertx.createNetClient(new NetClientOptions().setSoLinger(0)).connect(8080, "localhost", onSuccess(NetSocket::close)); vertx.createNetClient(new NetClientOptions().setSoLinger(0)).connect(8080, "localhost", onSuccess(NetSocket::close));
awaitLatch(resetLatch); awaitLatch(resetLatch);
assertNull(caught.get()); assertThat(caught.get(), instanceOf(IOException.class));
} }


@Override @Override
Expand All @@ -71,38 +74,4 @@ public void tearDown() throws Exception {
} }
super.tearDown(); super.tearDown();
} }

private class ResetLatchCountDown extends SimpleChannelInboundHandler<Object> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
}

@Override
public boolean acceptInboundMessage(Object msg) throws Exception {
return false;
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
ctx.executor().submit(resetLatch::countDown);
}
}

private class ThrowableRecorder extends SimpleChannelInboundHandler<Object> {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
}

@Override
public boolean acceptInboundMessage(Object msg) throws Exception {
return false;
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
super.exceptionCaught(ctx, cause);
caught.set(cause);
}
}
} }

0 comments on commit 815cce1

Please sign in to comment.