GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Auto-port 5.0: Propagate channelInactive during proxy negotiation (#1… · netty/netty@19447ce

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler-proxy/src
    • main/java/io/netty/handler/proxy
      • ProxyHandler.java
    • test/java/io/netty/handler/proxy
      • ProxyHandlerTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java‎

Copy file name to clipboardExpand all lines: handler-proxy/src/main/java/io/netty/handler/proxy/ProxyHandler.java
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,11 @@ protected final void sendToProxyServer(Object msg) {
243243

244244
@Override
245245
public final void channelInactive(ChannelHandlerContext ctx) throws Exception {
246-
if (finished) {
247-
ctx.fireChannelInactive();
248-
} else {
246+
if (!finished) {
249247
// Disconnected before connected to the destination.
250248
setConnectFailure(new ProxyConnectException(exceptionMessage("disconnected")));
251249
}
250+
ctx.fireChannelInactive();
252251
}
253252

254253
@Override
Collapse file

‎handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java‎

Copy file name to clipboardExpand all lines: handler-proxy/src/test/java/io/netty/handler/proxy/ProxyHandlerTest.java
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package io.netty.handler.proxy;
1818

1919
import io.netty.bootstrap.Bootstrap;
20+
import io.netty.bootstrap.ServerBootstrap;
2021
import io.netty.buffer.ByteBuf;
2122
import io.netty.buffer.PooledByteBufAllocator;
2223
import io.netty.buffer.Unpooled;
2324
import io.netty.channel.Channel;
2425
import io.netty.channel.ChannelHandler;
2526
import io.netty.channel.ChannelHandlerContext;
27+
import io.netty.channel.ChannelInboundHandler;
2628
import io.netty.channel.ChannelInitializer;
2729
import io.netty.channel.ChannelOption;
2830
import io.netty.channel.ChannelPipeline;
@@ -35,6 +37,7 @@
3537
import io.netty.channel.local.LocalIoHandler;
3638
import io.netty.channel.nio.NioIoHandler;
3739
import io.netty.channel.socket.SocketChannel;
40+
import io.netty.channel.socket.nio.NioServerSocketChannel;
3841
import io.netty.channel.socket.nio.NioSocketChannel;
3942
import io.netty.handler.codec.LineBasedFrameDecoder;
4043
import io.netty.handler.ssl.SslContext;
@@ -577,6 +580,64 @@ public boolean isActive() {
577580
assertThat(ch.finishAndReleaseAll()).isFalse();
578581
}
579582

583+
@ParameterizedTest(name = "{index}: {0}")
584+
@MethodSource("proxyTypes")
585+
public void testChannelInactiveWhenProxyDisconnectsDuringHandshake(String type) throws Exception {
586+
Channel server = new ServerBootstrap().group(group).channel(NioServerSocketChannel.class)
587+
.childHandler(new ChannelInitializer<SocketChannel>() {
588+
@Override
589+
protected void initChannel(SocketChannel ch) {
590+
ch.pipeline().addLast(new SimpleChannelInboundHandler<ByteBuf>() {
591+
@Override
592+
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
593+
// Disconnect after receiving the initial handshake message, without responding.
594+
ctx.close();
595+
}
596+
});
597+
}
598+
}).bind(NetUtil.LOCALHOST, 0).get();
599+
final ProxyHandler handler = newProxyHandler(type, server.localAddress());
600+
handler.setConnectTimeoutMillis(0);
601+
final Queue<Object> events = new LinkedBlockingQueue<Object>();
602+
final CountDownLatch unregistered = new CountDownLatch(1);
603+
Channel ch = null;
604+
try {
605+
ch = new Bootstrap().group(group).channel(NioSocketChannel.class)
606+
.resolver(NoopAddressResolverGroup.INSTANCE)
607+
.handler(new ChannelInitializer<SocketChannel>() {
608+
@Override
609+
protected void initChannel(SocketChannel ch) {
610+
ch.pipeline().addLast(handler, new ChannelInboundHandler() {
611+
@Override
612+
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
613+
events.add(cause);
614+
}
615+
616+
@Override
617+
public void channelInactive(ChannelHandlerContext ctx) {
618+
events.add("channelInactive");
619+
}
620+
621+
@Override
622+
public void channelUnregistered(ChannelHandlerContext ctx) {
623+
unregistered.countDown();
624+
}
625+
});
626+
}
627+
}).connect(DESTINATION).get();
628+
629+
assertThat(unregistered.await(10, TimeUnit.SECONDS)).isTrue();
630+
assertThat(handler.connectFuture().cause()).isInstanceOf(ProxyConnectException.class)
631+
.hasMessageContaining("disconnected");
632+
assertThat(events).containsExactly(handler.connectFuture().cause(), "channelInactive");
633+
} finally {
634+
if (ch != null) {
635+
ch.close().sync();
636+
}
637+
server.close().sync();
638+
}
639+
}
640+
580641
@AfterEach
581642
public void checkServerExceptions() throws Exception {
582643
for (ProxyServer p: allProxies) {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.