eclipse-vertx/vertx-sql-client

MSSQL - "The client can be redirected only once"

janicaud opened this issue · 8 comments

Questions

Do not use this issue tracker to ask questions, instead use one of these channels. Questions will likely be closed without notice.

Version

4.4.1 : no bug
4.4.2: bug

Context

In native, i've got the following trace :
The client can be redirected only once

Which seems to indicate that :

private Future<Connection> connectOrRedirect(MSSQLConnectOptions options, ContextInternal context, int redirections) {
    if (redirections > 1) {
      return context.failedFuture("The client can be redirected only once");
    }
    SocketAddress server = options.getSocketAddress();
    boolean clientSslConfig = options.isSsl();
    int desiredPacketSize = options.getPacketSize();
    // Always start unencrypted, the connection will be upgraded if client and server agree
    return client.connect(server)
      .map(so -> createSocketConnection(so, options, desiredPacketSize, context))
      .compose(conn -> conn.sendPreLoginMessage(clientSslConfig)
        .compose(encryptionLevel -> login(conn, options, encryptionLevel, context))
      )
      .compose(connBase -> {
        MSSQLSocketConnection conn = (MSSQLSocketConnection) connBase;
        SocketAddress 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));
      });
  }

SocketAddress alternateServer = conn.getAlternateServer(); is returning something

Cannot figure out where the alternate server is entered, the only clue is that the SQL Driver is trying a first time in unencrypted way to connect, and a second time using encryption.

Extra

'io.quarkus' version '3.1.0.Final' is not working, 3.0.1.Final is working

Using native mode embeded in a container

vietj commented

can you provide a reproducer project with test container ?

I think i have narrowed it to : i'm connecting to a Azure MS SQL Server, and actually there is a redirection :

xxxx.database.windows.net:1433
->
aaaaa.yyyy.northeuropezzzzworker.database.windows.net:11031

So typically, it triggers the alternate server path in the function, and then loop.

SocketAddress server = options.getSocketAddress();

should retrieve on the first redirect the alternate server not the original one. In the previous version, it was working because directly the SocketAddress was passed through the arguments, now it's only the options

Thanks for the details @janicaud !

@janicaud would you mind trying the patch in #1365 ?

Fixed by fbbb874

I can confirm the fix is working (Azure Web App + Azure SQL Database) with a snaphot build of 4.x branch