Bug #721 The ConnectorJ reconnect not working with 3.22.30 DB
Submitted: 25 Jun 2003 9:58 Modified: 26 Jun 2003 7:53
Reporter: Laszlo Szenttornyai Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S1 (Critical)
Version:Connector/J 3.0 OS:Linux (linux)
Assigned to: Mark Matthews CPU Architecture:Any

[25 Jun 2003 9:58] Laszlo Szenttornyai
Description:
The Connector/J offers a possibility to automatical reconnect to the server.

  setup.put( "autoReconnect", "true" );

Where setup is the connection property in the

  db = DriverManager.getConnection( url, setup );

But if the target mysql server is like
mysql  Ver 9.38 Distrib 3.22.30, for pc-linux-gnu (i686)
 AND
a reconnect enforced the following function fails:

com.mysql.jdbc.Connection.createNewIO

It is because the reconnection blindly skip the exception which happens in the reconnection attemp in the lines:

                        break;
                    } catch (Exception EEE) {
                        connectionGood = false;
                    }

unfortunatelly not only the reconnection failure event can happens but other exception like this:

--- JDBC reconnect failed [0/3] wait 2 sec
    connect to[0]smallball.com
java.sql.SQLException: Transaction Isolation Levels are not supported on MySQL versions older than 3.23.36.
        at com.mysql.jdbc.Connection.setTransactionIsolation(Connection.java:851)
        at com.mysql.jdbc.Connection.createNewIO(Connection.java:1667)

And this stop the reconnection even it is worked well in the first time.

How to repeat:
You need the 3.2 mysql server.
You need latest Connector/J
Edit com.mysql.jdbc.Connection.createNewIO like this:

                    } catch (Exception EEE) {
                      System.out.println( "--- JDBC reconnect failed ["+attemptCount+"/"+this.maxReconnects+"] wait "+((int)timeout)+" sec"  );
System.out.println(  "    connect to["+hostIndex+"]"+this.hostList.get(hostIndex) );
                    EEE.printStackTrace();
                        connectionGood = false;
                    }

Wait till the connection timeout happens with a db.
Try to use the connection watch the stack trace.

Suggested fix:
- remove the reconnect feature
- properly handle the transaction isolation request
- classify the excpetion

and most of all: throw meaningfull exception's
the number of attemp is something what I dont care, but the exception what cause the reconnection failure is
[26 Jun 2003 6:20] Mark Matthews
You don't say what version of Connector/J 3.0 you are using in this bug report (there are 8, plus nightly snapshots). It would help if you could tell me what version you are using.

> - remove the reconnect feature

You shouldn't use the feature if it doesn't have the behavior you expect. Other people depend on this feature working as it currently does. It is not enabled by default, so don't enable it if you don't want to use it.

> - properly handle the transaction isolation request

According to the JDBC spec, this method can not be a no-op if the database doesn't support transaction isolation and must throw an exception. You are using an old (3.23.30) version of MySQL that does not support transaction isolation. You should consider upgrading to a newer version of MySQL.

> - classify the excpetion

This is already fixed in Connector/J 3.1, and the fix will be backported to Connector/J 3.0.9.

Thank you for your bug report.
[26 Jun 2003 7:41] Laszlo Szenttornyai
Sorry, the JDBC version where I can verify this bug is the latest stable:
mysql-connector-java-3.0.8-stable.zip + mysql 3.22.30

Upgrading the mysql server is not an option for me, even I love to fix this problem that way.
[26 Jun 2003 7:53] Mark Matthews
I've fixed the code that tries to set transaction isolation on reconnect so that it won't attempt to do that on old MySQL versions. It will be available in Connector/J 3.0.9 and Connector/J 3.1.1, or you can download a nightly snapshot after 00:00 GMT today from http://mmmysql.sourceforge.net/snapshots/