From a8aed8b84d6ed30fe34193e9663f97768afadef1 Mon Sep 17 00:00:00 2001 From: Alexander Soklakov Date: Thu, 21 Feb 2019 12:06:30 +0400 Subject: [PATCH] WL#12459, Fix for async connection. --- .../com/mysql/cj/protocol/x/XProtocol.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/main/protocol-impl/java/com/mysql/cj/protocol/x/XProtocol.java b/src/main/protocol-impl/java/com/mysql/cj/protocol/x/XProtocol.java index c3dd54fd9..d94f958ed 100644 --- a/src/main/protocol-impl/java/com/mysql/cj/protocol/x/XProtocol.java +++ b/src/main/protocol-impl/java/com/mysql/cj/protocol/x/XProtocol.java @@ -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 tlsCapabilities = new HashMap<>(); + tlsCapabilities.put(XServerCapabilities.KEY_TLS, true); + sendCapabilities(tlsCapabilities); try { this.socketConnection.performTlsHandshake(null); //(this.serverSession); @@ -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) { @@ -318,6 +303,10 @@ public void beforeHandshake() { this.clientCapabilities.remove(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS); } } + + if (xdevapiSslMode.getValue() != XdevapiSslMode.DISABLED) { + negotiateSSLConnection(0); + } } private Map getConnectionAttributesMap(String attStr) { @@ -710,7 +699,9 @@ public void reset() { Map 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);