Skip to content

Commit 3260706

Browse files
committed
Update Azure MySQL detection. Fixes #731
1 parent a7e7aa7 commit 3260706

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public async Task ConnectAsync(ConnectionSettings cs, ILoadBalancer? loadBalance
443443
payload = await ReceiveReplyAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
444444
OkPayload.Create(payload.Span, SupportsDeprecateEof, SupportsSessionTrack);
445445

446-
if (ShouldGetRealServerDetails())
446+
if (ShouldGetRealServerDetails(cs))
447447
await GetRealServerDetailsAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
448448
}
449449
catch (ArgumentException ex)
@@ -1311,10 +1311,20 @@ bool ValidateRemoteCertificate(object rcbSender, X509Certificate rcbCertificate,
13111311
// Some servers are exposed through a proxy, which handles the initial handshake and gives the proxy's
13121312
// server version and thread ID. Detect this situation and return `true` if the real server's details should
13131313
// be requested after connecting (which takes an extra roundtrip).
1314-
private bool ShouldGetRealServerDetails()
1314+
private bool ShouldGetRealServerDetails(ConnectionSettings cs)
13151315
{
1316-
// currently hardcoded to the version returned by the Azure Database for MySQL proxy
1317-
return ServerVersion.OriginalString == "5.6.26.0" || ServerVersion.OriginalString == "5.6.39.0";
1316+
// currently hardcoded to the version(s) returned by the Azure Database for MySQL proxy
1317+
if (ServerVersion.OriginalString == "5.6.42.0" || ServerVersion.OriginalString == "5.6.39.0" || ServerVersion.OriginalString == "5.6.26.0")
1318+
return true;
1319+
1320+
// detect Azure Database for MySQL DNS suffixes
1321+
if (cs.ConnectionProtocol == MySqlConnectionProtocol.Sockets && cs.HostNames!.Count == 1)
1322+
{
1323+
return cs.HostNames[0].EndsWith(".mysql.database.azure.com", StringComparison.OrdinalIgnoreCase) ||
1324+
cs.HostNames[0].EndsWith(".mysql.database.chinacloudapi.cn", StringComparison.OrdinalIgnoreCase);
1325+
}
1326+
1327+
return false;
13181328
}
13191329

13201330
private async Task GetRealServerDetailsAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)