From 4bc31ae54623305ebfd2b774597c22fd0403cbbe Mon Sep 17 00:00:00 2001 From: Thomas Segismont Date: Wed, 25 Oct 2023 15:53:34 +0200 Subject: [PATCH] MSSQL Client routing regression (#1365) Fixes #1361 Signed-off-by: Thomas Segismont --- .../vertx/mssqlclient/impl/MSSQLConnectionFactory.java | 10 ++++++++-- .../vertx/mssqlclient/impl/MSSQLSocketConnection.java | 8 ++++---- .../vertx/mssqlclient/impl/codec/InitCommandCodec.java | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java index 3a0e37200..62c973ca7 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java @@ -16,6 +16,7 @@ import io.vertx.core.Promise; import io.vertx.core.impl.ContextInternal; import io.vertx.core.impl.VertxInternal; +import io.vertx.core.net.HostAndPort; import io.vertx.core.net.NetSocket; import io.vertx.core.net.SocketAddress; import io.vertx.core.net.impl.NetSocketInternal; @@ -60,13 +61,18 @@ private Future connectOrRedirect(MSSQLConnectOptions options, Contex ) .compose(connBase -> { MSSQLSocketConnection conn = (MSSQLSocketConnection) connBase; - SocketAddress alternateServer = conn.getAlternateServer(); + HostAndPort alternateServer = conn.getAlternateServer(); if (alternateServer == null) { return context.succeededFuture(conn); } Promise closePromise = context.promise(); conn.close(null, closePromise); - return closePromise.future().transform(v -> connectOrRedirect(options, context, redirections + 1)); + return closePromise.future().transform(v -> { + MSSQLConnectOptions connectOptions = new MSSQLConnectOptions(options) + .setHost(alternateServer.host()) + .setPort(alternateServer.port()); + return connectOrRedirect(connectOptions, context, redirections + 1); + }); }); } diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java index 0d34832fb..6142a6ee8 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java @@ -20,7 +20,7 @@ import io.vertx.core.impl.ContextInternal; import io.vertx.core.impl.future.PromiseInternal; import io.vertx.core.net.ClientSSLOptions; -import io.vertx.core.net.SocketAddress; +import io.vertx.core.net.HostAndPort; import io.vertx.core.net.impl.NetSocketInternal; import io.vertx.core.net.impl.SSLHelper; import io.vertx.core.net.impl.SslChannelProvider; @@ -52,7 +52,7 @@ public class MSSQLSocketConnection extends SocketConnectionBase { private final SSLHelper sslHelper; private MSSQLDatabaseMetadata databaseMetadata; - private SocketAddress alternateServer; + private HostAndPort alternateServer; MSSQLSocketConnection(NetSocketInternal socket, SSLHelper sslHelper, @@ -181,11 +181,11 @@ private void setDatabaseMetadata(MSSQLDatabaseMetadata metadata) { this.databaseMetadata = metadata; } - public SocketAddress getAlternateServer() { + public HostAndPort getAlternateServer() { return alternateServer; } - public void setAlternateServer(SocketAddress alternateServer) { + public void setAlternateServer(HostAndPort alternateServer) { this.alternateServer = alternateServer; } } diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java index 8ba62716d..44d919302 100644 --- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java +++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java @@ -12,7 +12,7 @@ package io.vertx.mssqlclient.impl.codec; import io.netty.buffer.ByteBuf; -import io.vertx.core.net.SocketAddress; +import io.vertx.core.net.HostAndPort; import io.vertx.mssqlclient.MSSQLConnectOptions; import io.vertx.mssqlclient.impl.MSSQLSocketConnection; import io.vertx.mssqlclient.impl.protocol.client.login.LoginPacket; @@ -220,6 +220,6 @@ protected void handleRouting(ByteBuf payload) { throw new IllegalStateException("ProtocolProperty value of zero is not allowed when Protocol is TCP-IP"); } String host = readUnsignedShortLengthString(payload); - conn.setAlternateServer(SocketAddress.inetSocketAddress(port, host.toLowerCase(ENGLISH))); + conn.setAlternateServer(HostAndPort.create(host.toLowerCase(ENGLISH), port)); } }