finagle
c86789cf0e06
finagle-netty4: Run the Netty4ProxyHandler connect promise later
Vladimir Kostyukov
1 day ago
Problem When Netty 4 proxy support is enabled, it's possible to satisfy the transport promise, and essentially start a client, before the underlying `ProxyHandler` removes its pieces from the pipeline. This leads to properly encoded messages being sent over the malformed pipeline. See https://github.com/netty/netty/issues/6671 Solution Run the connect promise satisfaction later, in the channel's event loop, and give the underlying `ProxyHandler` a chance to properly clean up the pipeline. RB_ID=915286

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
// React on satisfied proxy handshake promise. proxyHandler.connectFuture.addListener(new GenericFutureListener[NettyFuture[Channel]] { override def operationComplete(future: NettyFuture[Channel]): Unit = { if (future.isSuccess) {
// We "try" because it might be already cancelled and we don't need to handle // cancellations here - it's already done by `proxyCancellationsTo`. // Same thing about `tryFailure` below. if (promise.trySuccess()) { ctx.pipeline().remove(proxyCodecKey) ctx.pipeline().remove(self) }
ctx.pipeline().remove(proxyCodecKey) ctx.pipeline().remove(self) // We have to run the connect `promise` satisfaction later so we give `ProxyHandler` // a chance to clean up the pipeline (remove its proxy codecs) before we start // sending traffic. ctx.executor().submit(new Runnable { def run(): Unit = promise.trySuccess() })
} else { // SOCKS/HTTP proxy handshake promise is failed so given `ProxyHandler` is going to // close the channel and fail pending writes, we only need to fail the connect promise. promise.tryFailure(future.cause()) }
About FluentSend Feedback