Skip to content

Java Driver: New handshake broke .reconnect() #5841

@bchavez

Description

@bchavez

I was noticing some weird behavior in the C# driver with the connection pooling code. I noticed, when Connection.Close() is called, any attempts to .Reconnect(), the reconnect always fails even if the TCP physical socket connection was okay.

I think this is due some internal Handshake state that is not being .reset() when the reconnect is attempted.

Handshake.java
    public Handshake(String username, String password) {
        this.username = username;
        this.password = password;
        this.state = new InitialState(username, password);
    }

    public void reset() {
        this.state = new InitialState(this.username, this.password);
    }

And there's some code here that kinda sits here except, on the 2nd time around, the Handshake was finished from the 1st attempt. 🎱

void connect(Handshake handshake){
....
            while(!handshake.isFinished()) {
                if (toWrite.isPresent()) {
                    write(toWrite.get());
                }
                String serverMsg = readNullTerminatedString(deadline);
                toWrite = handshake.nextMessage(serverMsg);
            }
....
}

So, the reconnect results in no re-authentication...

Handshake.reset() is nowhere to be found in Connection.java or in SocketWrapper.java

The pythin 🐍 code seems to Handshake.reset() in something like ConnectionInstance?

My fix in the C# driver is in SocketWrapper.cs / UnitTest. _I think_ this would be the right place for the reset. Also, seems to have resolved my .Reconnect issue in the C# driver. 😸

Let me knoooooooo what your thinking and I'll submit a PR for ya.

Muchas gracias,
Brian

💭 🔍 _"I want to know... what you're thinking..."_

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions