Bug #45021 | MySQL Connector/Net should show better error text when socket exception occurs | ||
---|---|---|---|
Submitted: | 22 May 2009 3:26 | Modified: | 18 Jun 2009 10:33 |
Reporter: | Christopher Jerdonek | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 5.2.6 | OS: | Windows (XP SP3) |
Assigned to: | CPU Architecture: | Any | |
Tags: | connect, Connection, exception, hosts, port, socket, specified, tcp |
[22 May 2009 3:26]
Christopher Jerdonek
[22 May 2009 21:31]
Christopher Jerdonek
I checked out the Connector/Net 5.2.6 code, and the relevant section of code appears to be here. This is in the implementation of the MySql.Data.Common.StreamCreator.CreateSocketStream(IPAddress ip, bool unix) method: try { socket.EndConnect(ias); } catch (Exception) { socket.Close(); return null; } Is there any reason not to re-throw the exception here so the caller can see it? Perhaps you can adjust the code as follows: try { socket.EndConnect(ias); } catch (Exception) { socket.Close(); throw; } And then in StreamCreator.GetStream(uint timeout) (which is the only place that calls CreateSocketStream), you can adjust the second CreateSocketStream call in the foreach loop to something like the following: try { stream = CreateSocketStream(address, false); } catch (Exception) { // "throw" or "continue" in this catch block // depending on whether there are more // IP addresses to consider in the dnsHosts list // and associated ipHE address lists. For // example, if there are more addresses to // consider, then you can bury the exception, // and continue on with the other addresses to // come in the two while/foreach loops. // throw; // continue; } Question: are there actually circumstances where a SocketException is valid in the above foreach loop, and you would want to ignore the exception and continue on to the next IP address? In other words, why not always rethrow the exception since it is an error state?
[29 May 2009 20:47]
Bugs System
A patch for this bug has been committed. After review, it may be pushed to the relevant source trees for release in the next version. You can access the patch from: http://lists.mysql.com/commits/75295
[29 May 2009 20:48]
Reggie Burnett
fixed in 5.2.7 and 6.0.4+
[18 Jun 2009 10:33]
Tony Bedford
An entry was added to both the 5.2.7 and 6.0.4 changelogs: If a certain socket exception occurred when trying to establish a MySQL database connection, MySQL Connector/NET displayed an exception message that appeared to be unrelated to the underlying problem. This masked the problem and made diagnosing problems more difficult. For example, if, when establishing a database connection via TCP/IP, Windows on the local machine allocated an ephemeral port that conflicted with a socket address still in use, then Windows/.NET would throw a socket exception with the following error text: Only one usage of each socket address (protocol/network address/port) is normally permitted IP ADDRESS/PORT. However, Connector/NET masked this socket exception and displayed an exception with the following text: Unable to connect to any of the specified MySQL hosts.