From d48f7834d2c50eab3d17fd89cce0c728b993dee6 Mon Sep 17 00:00:00 2001 From: Julien Viet Date: Sat, 1 Jul 2017 23:30:15 +0200 Subject: [PATCH] Closed Http1x connections must be removed from the client connection map when the connection becomes inactive --- .../java/io/vertx/core/http/impl/Http1xPool.java | 1 + .../vertx/core/http/impl/Http2ConnectionBase.java | 15 +++------------ .../io/vertx/core/net/impl/ConnectionBase.java | 6 ++++++ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main/java/io/vertx/core/http/impl/Http1xPool.java b/src/main/java/io/vertx/core/http/impl/Http1xPool.java index b6cd0cde63e..31086c4b984 100644 --- a/src/main/java/io/vertx/core/http/impl/Http1xPool.java +++ b/src/main/java/io/vertx/core/http/impl/Http1xPool.java @@ -168,6 +168,7 @@ void createConn(HttpVersion version, ContextImpl context, int port, String host, // gets the closed on, they will check if it's closed and if so get another one. private synchronized void connectionClosed(ClientConnection conn) { synchronized (queue) { + connectionMap.remove(conn.channel()); allConnections.remove(conn); availableConnections.remove(conn); queue.connectionClosed(); diff --git a/src/main/java/io/vertx/core/http/impl/Http2ConnectionBase.java b/src/main/java/io/vertx/core/http/impl/Http2ConnectionBase.java index 85ceba79ccb..f2c8cf0a2a6 100644 --- a/src/main/java/io/vertx/core/http/impl/Http2ConnectionBase.java +++ b/src/main/java/io/vertx/core/http/impl/Http2ConnectionBase.java @@ -78,8 +78,7 @@ static ByteBuf safeBuffer(ByteBuf buf, ByteBufAllocator allocator) { } protected final IntObjectMap streams = new IntObjectHashMap<>(); - protected ChannelHandlerContext handlerContext; - protected final Channel channel; + protected final ChannelHandlerContext handlerContext; protected final VertxHttp2ConnectionHandler handler; private boolean shutdown; private Handler clientSettingsHandler; @@ -94,9 +93,8 @@ static ByteBuf safeBuffer(ByteBuf buf, ByteBufAllocator allocator) { public Http2ConnectionBase(ContextImpl context, VertxHttp2ConnectionHandler handler) { super(context.owner(), handler.context(), context); - this.channel = handler.context().channel(); - this.handlerContext = channel.pipeline().context(handler); this.handler = handler; + this.handlerContext = chctx; this.windowSize = handler.connection().local().flowController().windowSize(handler.connection().connectionStream()); } @@ -337,7 +335,7 @@ public synchronized HttpConnection shutdown(long timeout) { throw new IllegalArgumentException("Invalid timeout value " + timeout); } handler.gracefulShutdownTimeoutMillis(timeout); - channel.close(); + channel().close(); return this; } @@ -449,13 +447,6 @@ public synchronized Http2ConnectionBase exceptionHandler(Handler hand return (Http2ConnectionBase) super.exceptionHandler(handler); } - /** - * @return the Netty channel - for internal usage only - */ - public Channel channel() { - return channel; - } - // Private private void checkShutdownHandler() { diff --git a/src/main/java/io/vertx/core/net/impl/ConnectionBase.java b/src/main/java/io/vertx/core/net/impl/ConnectionBase.java index db633683617..d44c0c4cea7 100644 --- a/src/main/java/io/vertx/core/net/impl/ConnectionBase.java +++ b/src/main/java/io/vertx/core/net/impl/ConnectionBase.java @@ -179,6 +179,12 @@ protected void checkContext() { } } + /** + * @return the Netty channel - for internal usage only + */ + public Channel channel() { + return chctx.channel(); + } public ContextImpl getContext() { return context;