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 authored Oct 25, 2023
1 parent 9cf145a commit 5b504d0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
import io.vertx.core.impl.ContextInternal;
import io.vertx.core.impl.EventLoopContext;
import io.vertx.core.impl.VertxInternal;
import io.vertx.core.net.NetClient;
import io.vertx.core.net.NetClientOptions;
import io.vertx.core.net.NetSocket;
import io.vertx.core.net.SocketAddress;
import io.vertx.core.net.*;
import io.vertx.core.net.impl.NetSocketInternal;
import io.vertx.core.spi.metrics.ClientMetrics;
import io.vertx.core.spi.metrics.VertxMetrics;
Expand Down Expand Up @@ -62,13 +59,18 @@ private Future<Connection> connectOrRedirect(MSSQLConnectOptions options, EventL
)
.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 @@ -19,7 +19,7 @@
import io.vertx.core.Handler;
import io.vertx.core.impl.EventLoopContext;
import io.vertx.core.impl.future.PromiseInternal;
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.SslHandshakeCompletionHandler;
Expand Down Expand Up @@ -49,7 +49,7 @@ public class MSSQLSocketConnection extends SocketConnectionBase {
private final int packetSize;

private MSSQLDatabaseMetadata databaseMetadata;
private SocketAddress alternateServer;
private HostAndPort alternateServer;

MSSQLSocketConnection(NetSocketInternal socket,
ClientMetrics clientMetrics,
Expand Down Expand Up @@ -173,11 +173,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 5b504d0

Please sign in to comment.