Skip to content

Commit a8aed8b

Browse files
committed
WL#12459, Fix for async connection.
1 parent 1c2d62d commit a8aed8b

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

src/main/protocol-impl/java/com/mysql/cj/protocol/x/XProtocol.java

+11-20
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,9 @@ public void negotiateSSLConnection(int packLength) {
200200
// the message reader is async and is always "reading". we need to stop it to use the socket for the TLS handshake
201201
this.reader.stopAfterNextMessage();
202202

203-
this.clientCapabilities.put(XServerCapabilities.KEY_TLS, true);
204-
205-
try {
206-
sendCapabilities(this.clientCapabilities);
207-
} catch (XProtocolError e) {
208-
// XProtocolError: ERROR 5002 (HY000) Capability 'session_connect_attrs' doesn't exist
209-
// happens when connecting to xplugin which doesn't support this feature.
210-
// Just ignore this error and retry with reduced clientCapabilities
211-
if (e.getErrorCode() != 5002 && !e.getMessage().contains(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS)) {
212-
throw e;
213-
}
214-
this.clientCapabilities.remove(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS);
215-
this.reader.start();
216-
this.reader.stopAfterNextMessage();
217-
sendCapabilities(this.clientCapabilities);
218-
}
203+
Map<String, Object> tlsCapabilities = new HashMap<>();
204+
tlsCapabilities.put(XServerCapabilities.KEY_TLS, true);
205+
sendCapabilities(tlsCapabilities);
219206

220207
try {
221208
this.socketConnection.performTlsHandshake(null); //(this.serverSession);
@@ -304,9 +291,7 @@ public void beforeHandshake() {
304291
throw new CJCommunicationsException(msg.toString());
305292
}
306293

307-
if (xdevapiSslMode.getValue() != XdevapiSslMode.DISABLED) {
308-
negotiateSSLConnection(0);
309-
} else if (this.clientCapabilities.size() > 0) {
294+
if (this.clientCapabilities.size() > 0) {
310295
try {
311296
sendCapabilities(this.clientCapabilities);
312297
} catch (XProtocolError e) {
@@ -318,6 +303,10 @@ public void beforeHandshake() {
318303
this.clientCapabilities.remove(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS);
319304
}
320305
}
306+
307+
if (xdevapiSslMode.getValue() != XdevapiSslMode.DISABLED) {
308+
negotiateSSLConnection(0);
309+
}
321310
}
322311

323312
private Map<String, String> getConnectionAttributesMap(String attStr) {
@@ -710,7 +699,9 @@ public void reset() {
710699
Map<String, Object> reducedClientCapabilities = new HashMap<>();
711700
reducedClientCapabilities.put(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS,
712701
this.clientCapabilities.get(XServerCapabilities.KEY_SESSION_CONNECT_ATTRS));
713-
sendCapabilities(reducedClientCapabilities);
702+
if (reducedClientCapabilities.size() > 0) {
703+
sendCapabilities(reducedClientCapabilities);
704+
}
714705
}
715706

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

0 commit comments

Comments
 (0)