Modified:
trunk/src/com/mysql/jdbc/MysqlIOprotocol.java
Log:
Catch socket-related exceptions and convert to CommunicationExceptions early on. The factory-ization of MysqlIO caused these exceptions to be genericized, thus breaking failover, reconnect, etc.
Modified: trunk/src/com/mysql/jdbc/MysqlIOprotocol.java
===================================================================
--- trunk/src/com/mysql/jdbc/MysqlIOprotocol.java 2008-05-29 02:27:46 UTC (rev 6782)
+++ trunk/src/com/mysql/jdbc/MysqlIOprotocol.java 2008-05-29 02:29:23 UTC (rev 6783)
@@ -34,6 +34,7 @@
import java.io.OutputStreamWriter;
import java.lang.ref.SoftReference;
import java.math.BigInteger;
+import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
@@ -285,57 +286,62 @@
.get(ConnectionPropertiesImpl.SOCKET_FACTORY_PROPERTY_KEY);
this.socketFactory = createSocketFactory();
- this.mysqlConnection = this.socketFactory.connect(this.host,
+ try {
+ this.mysqlConnection = this.socketFactory.connect(this.host,
this.port, props);
-
- int socketTimeout = Integer.parseInt((String) props
- .get(ConnectionPropertiesImpl.SOCKET_TIMEOUT_PROPERTY_KEY));
- if (socketTimeout != 0) {
- try {
- this.mysqlConnection.setSoTimeout(socketTimeout);
- } catch (Exception ex) {
- /* Ignore if the platform does not support it */
- }
+
+ int socketTimeout = Integer.parseInt((String) props
+ .get(ConnectionPropertiesImpl.SOCKET_TIMEOUT_PROPERTY_KEY));
+ if (socketTimeout != 0) {
+ try {
+ this.mysqlConnection.setSoTimeout(socketTimeout);
+ } catch (Exception ex) {
+ /* Ignore if the platform does not support it */
+ }
+ }
+
+ this.mysqlConnection = this.socketFactory.beforeHandshake();
+
+ if (this.connection.getUseReadAheadInput()) {
+ this.mysqlInput = new ReadAheadInputStream(this.mysqlConnection.getInputStream(), 16384,
+ this.connection.getTraceProtocol(),
+ this.connection.getLog());
+ } else if (this.connection.useUnbufferedInput()) {
+ this.mysqlInput = this.mysqlConnection.getInputStream();
+ } else {
+ this.mysqlInput = new BufferedInputStream(this.mysqlConnection.getInputStream(),
+ 16384);
+ }
+
+ this.mysqlOutput = new BufferedOutputStream(this.mysqlConnection.getOutputStream(),
+ 16384);
+
+
+ this.isInteractiveClient = this.connection.getInteractiveClient();
+ this.profileSql = this.connection.getProfileSql();
+ this.sessionCalendar = Calendar.getInstance();
+ this.autoGenerateTestcaseScript = this.connection.getAutoGenerateTestcaseScript();
+
+ this.needToGrabQueryFromPacket = (this.profileSql ||
+ this.logSlowQueries ||
+ this.autoGenerateTestcaseScript);
+
+ if (this.connection.getUseNanosForElapsedTime()
+ && Util.nanoTimeAvailable()) {
+ this.useNanosForElapsedTime = true;
+
+ this.queryTimingUnits = Messages.getString("Nanoseconds");
+ } else {
+ this.queryTimingUnits = Messages.getString("Milliseconds");
+ }
+
+ if (this.connection.getLogSlowQueries()) {
+ calculateSlowQueryThreshold();
+ }
+ } catch (IOException ioEx) {
+ throw SQLError.createCommunicationsException(this.connection,
+ this.lastPacketSentTimeMs, this.lastPacketReceivedTimeMs, ioEx);
}
-
- this.mysqlConnection = this.socketFactory.beforeHandshake();
-
- if (this.connection.getUseReadAheadInput()) {
- this.mysqlInput = new ReadAheadInputStream(this.mysqlConnection.getInputStream(), 16384,
- this.connection.getTraceProtocol(),
- this.connection.getLog());
- } else if (this.connection.useUnbufferedInput()) {
- this.mysqlInput = this.mysqlConnection.getInputStream();
- } else {
- this.mysqlInput = new BufferedInputStream(this.mysqlConnection.getInputStream(),
- 16384);
- }
-
- this.mysqlOutput = new BufferedOutputStream(this.mysqlConnection.getOutputStream(),
- 16384);
-
-
- this.isInteractiveClient = this.connection.getInteractiveClient();
- this.profileSql = this.connection.getProfileSql();
- this.sessionCalendar = Calendar.getInstance();
- this.autoGenerateTestcaseScript = this.connection.getAutoGenerateTestcaseScript();
-
- this.needToGrabQueryFromPacket = (this.profileSql ||
- this.logSlowQueries ||
- this.autoGenerateTestcaseScript);
-
- if (this.connection.getUseNanosForElapsedTime()
- && Util.nanoTimeAvailable()) {
- this.useNanosForElapsedTime = true;
-
- this.queryTimingUnits = Messages.getString("Nanoseconds");
- } else {
- this.queryTimingUnits = Messages.getString("Milliseconds");
- }
-
- if (this.connection.getLogSlowQueries()) {
- calculateSlowQueryThreshold();
- }
}
public void initializeStatementInterceptors(String interceptorClasses,
| Thread |
|---|
| • Connector/J commit: r6783 - trunk/src/com/mysql/jdbc | mmatthews | 29 May |