From 335c079f82e83b8ead46a21020c768256f147345 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Wed, 21 Oct 2026 20:04:34 -0400 Subject: [PATCH] OmnibusH2ServerTest: do pipeline configuration in a channel handler --- .../grpc/net/OmnibusH2ServerTest.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2ServerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2ServerTest.java index 438fecd6f..5cdcd0eaa 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2ServerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/grpc/net/OmnibusH2ServerTest.java @@ -730,6 +730,7 @@ class OmnibusH2ServerTest { /// Makes an H2 connection to the omnibus at `server` on which new H2 streams can be opened private Channel connectToOmnibus(final OmnibusH2Server server, @Nullable final HAProxyMessage proxyHeader) { final SslContext clientSsl = sslContext(); + final CompletableFuture pipelineConfigured = new CompletableFuture<>(); final Bootstrap clientBootstrap = new Bootstrap() .group(nioEventLoopGroup) @@ -741,23 +742,34 @@ class OmnibusH2ServerTest { @Override protected void initChannel(final SocketChannel ch) { ch.pipeline().addLast(HAProxyMessageEncoder.INSTANCE); + ch.pipeline().addLast(new ChannelInboundHandlerAdapter() { + @Override + public void channelActive(final ChannelHandlerContext ctx) { + // The TLS and HTTP/2 handlers can't be added until after the proxy header is written + if (proxyHeader != null) { + ctx.writeAndFlush(proxyHeader); + } + ctx.pipeline().remove(HAProxyMessageEncoder.INSTANCE); + ctx.pipeline().remove(this); + ctx.pipeline().addLast(clientSsl.newHandler(ctx.alloc(), server.getLocalAddress().getHostName(), server.getLocalAddress().getPort())); + ctx.pipeline().addLast(Http2FrameCodecBuilder.forClient() + .initialSettings(Http2Settings.defaultSettings()) + .build()); + ctx.pipeline().addLast(new Http2MultiplexHandler(new ChannelInboundHandlerAdapter())); + pipelineConfigured.complete(null); + } + }); } }); final Channel ch = clientBootstrap.connect(server.getLocalAddress()) .syncUninterruptibly() .channel(); - if (proxyHeader != null) { - ch.writeAndFlush(proxyHeader).syncUninterruptibly(); - } - ch.pipeline().remove(HAProxyMessageEncoder.INSTANCE); - ch.pipeline().addLast(clientSsl.newHandler(ch.alloc(), server.getLocalAddress().getHostName(), server.getLocalAddress().getPort())); - ch.pipeline().addLast(Http2FrameCodecBuilder.forClient() - .initialSettings(Http2Settings.defaultSettings()) - .build()); - ch.pipeline().addLast(new Http2MultiplexHandler(new ChannelInboundHandlerAdapter())); + // The connect future completes before channelActive fires, so wait until streams can actually be opened + pipelineConfigured.orTimeout(5, TimeUnit.SECONDS).join(); return ch; } + private Channel connectToOmnibus(final OmnibusH2Server server) { return connectToOmnibus(server, null); }