Skip to content

Commit

Permalink
WL#12459, Fix for async connection.
Browse files Browse the repository at this point in the history
  • Loading branch information
soklakov committed Feb 21, 2019
1 parent 1c2d62d commit a8aed8b
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions src/main/protocol-impl/java/com/mysql/cj/protocol/x/XProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,9 @@ public void negotiateSSLConnection(int packLength) {
// the message reader is async and is always "reading". we need to stop it to use the socket for the TLS handshake
this.reader.stopAfterNextMessage();

this.clientCapabilities.put(XServerCapabilities.KEY_TLS, true);

try {
sendCapabilities(this.clientCapabilities);
} catch (XProtocolError e) {
// XProtocolError: ERROR 5002 (HY000) Capability 'session_connect_attrs' doesn't exist
// happens when connecting to xplugin which doesn't support this feature.
// Just ignore this error and retry with reduced clientCapabilities
if (e.getErrorCode() != 5002 && !e.getMessage().contains(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS)) {
throw e;
}
this.clientCapabilities.remove(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS);
this.reader.start();
this.reader.stopAfterNextMessage();
sendCapabilities(this.clientCapabilities);
}
Map<String, Object> tlsCapabilities = new HashMap<>();
tlsCapabilities.put(XServerCapabilities.KEY_TLS, true);
sendCapabilities(tlsCapabilities);

try {
this.socketConnection.performTlsHandshake(null); //(this.serverSession);
Expand Down Expand Up @@ -304,9 +291,7 @@ public void beforeHandshake() {
throw new CJCommunicationsException(msg.toString());
}

if (xdevapiSslMode.getValue() != XdevapiSslMode.DISABLED) {
negotiateSSLConnection(0);
} else if (this.clientCapabilities.size() > 0) {
if (this.clientCapabilities.size() > 0) {
try {
sendCapabilities(this.clientCapabilities);
} catch (XProtocolError e) {
Expand All @@ -318,6 +303,10 @@ public void beforeHandshake() {
this.clientCapabilities.remove(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS);
}
}

if (xdevapiSslMode.getValue() != XdevapiSslMode.DISABLED) {
negotiateSSLConnection(0);
}
}

private Map<String, String> getConnectionAttributesMap(String attStr) {
Expand Down Expand Up @@ -710,7 +699,9 @@ public void reset() {
Map<String, Object> reducedClientCapabilities = new HashMap<>();
reducedClientCapabilities.put(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS,
this.clientCapabilities.get(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS));
sendCapabilities(reducedClientCapabilities);
if (reducedClientCapabilities.size() > 0) {
sendCapabilities(reducedClientCapabilities);
}
}

this.authProvider.changeUser(null, this.currUser, this.currPassword, this.currDatabase);
Expand Down

0 comments on commit a8aed8b

Please sign in to comment.