Skip to content

Commit fbbb874

Browse files
committed
MSSQL Client routing regression (#1365)
Fixes #1361 Signed-off-by: Thomas Segismont <[email protected]>
1 parent c20effa commit fbbb874

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLConnectionFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
import io.vertx.core.Promise;
1717
import io.vertx.core.impl.ContextInternal;
1818
import io.vertx.core.impl.VertxInternal;
19-
import io.vertx.core.net.NetClient;
20-
import io.vertx.core.net.NetClientOptions;
21-
import io.vertx.core.net.NetSocket;
22-
import io.vertx.core.net.SocketAddress;
19+
import io.vertx.core.net.*;
2320
import io.vertx.core.net.impl.NetSocketInternal;
2421
import io.vertx.core.spi.metrics.ClientMetrics;
2522
import io.vertx.core.spi.metrics.VertxMetrics;
@@ -61,13 +58,18 @@ private Future<Connection> connectOrRedirect(MSSQLConnectOptions options, Contex
6158
)
6259
.compose(connBase -> {
6360
MSSQLSocketConnection conn = (MSSQLSocketConnection) connBase;
64-
SocketAddress alternateServer = conn.getAlternateServer();
61+
HostAndPort alternateServer = conn.getAlternateServer();
6562
if (alternateServer == null) {
6663
return context.succeededFuture(conn);
6764
}
6865
Promise<Void> closePromise = context.promise();
6966
conn.close(null, closePromise);
70-
return closePromise.future().transform(v -> connectOrRedirect(options, context, redirections + 1));
67+
return closePromise.future().transform(v -> {
68+
MSSQLConnectOptions connectOptions = new MSSQLConnectOptions(options)
69+
.setHost(alternateServer.host())
70+
.setPort(alternateServer.port());
71+
return connectOrRedirect(connectOptions, context, redirections + 1);
72+
});
7173
});
7274
}
7375

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/MSSQLSocketConnection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import io.vertx.core.Handler;
2020
import io.vertx.core.impl.ContextInternal;
2121
import io.vertx.core.impl.future.PromiseInternal;
22-
import io.vertx.core.net.SocketAddress;
22+
import io.vertx.core.net.HostAndPort;
2323
import io.vertx.core.net.impl.NetSocketInternal;
2424
import io.vertx.core.net.impl.SSLHelper;
2525
import io.vertx.core.net.impl.SslHandshakeCompletionHandler;
@@ -49,7 +49,7 @@ public class MSSQLSocketConnection extends SocketConnectionBase {
4949
private final int packetSize;
5050

5151
private MSSQLDatabaseMetadata databaseMetadata;
52-
private SocketAddress alternateServer;
52+
private HostAndPort alternateServer;
5353

5454
MSSQLSocketConnection(NetSocketInternal socket,
5555
ClientMetrics clientMetrics,
@@ -173,11 +173,11 @@ private void setDatabaseMetadata(MSSQLDatabaseMetadata metadata) {
173173
this.databaseMetadata = metadata;
174174
}
175175

176-
public SocketAddress getAlternateServer() {
176+
public HostAndPort getAlternateServer() {
177177
return alternateServer;
178178
}
179179

180-
public void setAlternateServer(SocketAddress alternateServer) {
180+
public void setAlternateServer(HostAndPort alternateServer) {
181181
this.alternateServer = alternateServer;
182182
}
183183
}

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
package io.vertx.mssqlclient.impl.codec;
1313

1414
import io.netty.buffer.ByteBuf;
15-
import io.vertx.core.net.SocketAddress;
15+
import io.vertx.core.net.HostAndPort;
1616
import io.vertx.mssqlclient.MSSQLConnectOptions;
1717
import io.vertx.mssqlclient.impl.MSSQLSocketConnection;
1818
import io.vertx.mssqlclient.impl.protocol.client.login.LoginPacket;
@@ -220,6 +220,6 @@ protected void handleRouting(ByteBuf payload) {
220220
throw new IllegalStateException("ProtocolProperty value of zero is not allowed when Protocol is TCP-IP");
221221
}
222222
String host = readUnsignedShortLengthString(payload);
223-
conn.setAlternateServer(SocketAddress.inetSocketAddress(port, host.toLowerCase(ENGLISH)));
223+
conn.setAlternateServer(HostAndPort.create(host.toLowerCase(ENGLISH), port));
224224
}
225225
}

0 commit comments

Comments
 (0)