Skip to content

Commit 59c450c

Browse files
committed
Throw MySqlException for invalid port number.
1 parent 0310ad2 commit 59c450c

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ public async Task ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer
301301
if (ShouldGetRealServerDetails())
302302
await GetRealServerDetailsAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
303303
}
304+
catch (ArgumentException ex)
305+
{
306+
m_logArguments[1] = ex.Message;
307+
Log.Error("{0} couldn't connect to server: {1}", m_logArguments);
308+
throw new MySqlException("Couldn't connect to server", ex);
309+
}
304310
catch (IOException ex)
305311
{
306312
m_logArguments[1] = ex.Message;

tests/SideBySide/ConnectSync.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ public void ConnectBadPort()
4545
}
4646
}
4747

48+
[Fact]
49+
public void ConnectInvalidPort()
50+
{
51+
var csb = new MySqlConnectionStringBuilder
52+
{
53+
Server = "localhost",
54+
Port = 1000000,
55+
};
56+
using (var connection = new MySqlConnection(csb.ConnectionString))
57+
{
58+
Assert.Throws<MySqlException>(() => connection.Open());
59+
}
60+
}
61+
4862
[Fact]
4963
public void ConnectBadDatabase()
5064
{

0 commit comments

Comments
 (0)