Skip to content

Commit

Permalink
MSSQL Client routing regression (#1365)
Browse files Browse the repository at this point in the history
Fixes #1361

Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont committed Oct 25, 2023
1 parent 68eb652 commit 4bc31ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,13 +61,18 @@ private Future<Connection> 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<Void> 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);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 4bc31ae

Please sign in to comment.