Skip to content

Commit 5d47460

Browse files
committed
NetSocket implementation should resume reading after a TLS upgrade failure.
Motivation: The recent channel TLS upgrade changes introduced a regression: the channel was only resumed on a success and not on a failure. When a channel handler performs a TLS upgrade via the NetSocket API and fires a message, this message was not read by the NetSocket and ignored. The NetSocket was still closed but the opportunity to consume the message was lost. Changes: Always resume reading the NetSocket after an upgrade result.
1 parent db31177 commit 5d47460

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

vertx-core/src/main/java/io/vertx/core/net/impl/tcp/NetSocketImpl.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ private Future<Void> sslUpgrade(String serverName, SSLOptions sslOptions, ByteBu
167167
});
168168
return p.future();
169169
}).transform(ar -> {
170-
if (ar.succeeded()) {
171-
doResume();
172-
}
170+
doResume();
173171
return (Future<Void>) ar;
174172
});
175173
} else {

vertx-core/src/test/java/io/vertx/tests/net/NetTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
import io.vertx.core.spi.tls.SslContextFactory;
4848
import io.vertx.core.transport.Transport;
4949
import io.vertx.test.core.*;
50+
import io.vertx.test.fakedns.DnsRecord;
51+
import io.vertx.test.fakedns.DnsServer;
52+
import io.vertx.test.fakedns.WithDnsServer;
5053
import io.vertx.test.proxy.*;
5154
import io.vertx.test.tls.Cert;
5255
import io.vertx.test.tls.Trust;
@@ -89,6 +92,9 @@
8992
@RunWith(VertxRunner.class)
9093
public class NetTest {
9194

95+
@Rule
96+
public final DnsServer dnsServer = new DnsServer();
97+
9298
public static class Provider implements VertxProvider {
9399

94100
public VertxOptions options() {
@@ -2114,6 +2120,51 @@ public void testDirectTlsUpgrade(Checkpoint checkpoint) throws Exception {
21142120
socket.write("test").await();
21152121
}
21162122

2123+
@WithDnsServer(records = {@DnsRecord(name = "example.com")})
2124+
@Test
2125+
public void testDirectTlsUpgradeFailureResumeReading(Checkpoint checkpoint) throws Exception {
2126+
server = vertx.createNetServer(new NetServerOptions()
2127+
.setSsl(true)
2128+
.setKeyCertOptions(Cert.SERVER_JKS.get())
2129+
).connectHandler(so -> {
2130+
fail();
2131+
});
2132+
server.listen(1234, "localhost").await();
2133+
Future<NetSocket> future = client.connect(new ConnectOptions()
2134+
.setPort(1234)
2135+
.setHost("example.com")
2136+
.setSslOptions(new ClientSSLOptions()
2137+
.setHostnameVerificationAlgorithm("HTTPS")
2138+
.setTrustAll(true)));
2139+
future.onComplete(TestUtils.onSuccess(socket -> {
2140+
NetSocketInternal soi = (NetSocketInternal) socket;
2141+
ChannelPipeline pipeline = soi
2142+
.channelHandlerContext()
2143+
.pipeline();
2144+
Object expectedMsg = new Object();
2145+
AtomicBoolean closed = new AtomicBoolean();
2146+
pipeline.addBefore("handler", "test", new ChannelDuplexHandler() {
2147+
@Override
2148+
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
2149+
soi
2150+
.upgradeToSsl()
2151+
.onComplete(TestUtils.onFailure(err -> {
2152+
assertFalse(closed.get());
2153+
ctx.fireChannelRead(expectedMsg);
2154+
}));
2155+
}
2156+
});
2157+
soi.closeHandler(v -> {
2158+
closed.set(true);
2159+
});
2160+
soi.messageHandler(msg -> {
2161+
if (msg == expectedMsg) {
2162+
checkpoint.succeed();
2163+
}
2164+
});
2165+
}));
2166+
}
2167+
21172168
public static class NativeVertxProvider implements VertxProvider {
21182169
@Override
21192170
public Vertx call() throws Exception {

0 commit comments

Comments
 (0)