Bug #15405 Connections are never re-esablished after failure
Submitted: 1 Dec 2005 20:34 Modified: 23 Feb 2006 8:29
Reporter: Steve Green Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:3.1.12 OS:Linux (Red Hat Enterprise Linux WS rele)
Assigned to: CPU Architecture:Any

[1 Dec 2005 20:34] Steve Green
Description:
After the server closes a connection, the connector is supposed to reconnect but it never does (under default conditions).

How to repeat:
We are using hibernate but I suppose you could commit a transaction, restart mysql and try it again.  It should fail and never recover.

Suggested fix:
One possible explanation is this line in Connection.java:commit()

    } finally {
        this.needsPing = this.getReconnectAtTxEnd();
    }

Under failure conditions, needsPing is set to TRUE thus enabling a recconect on the next transaction, but this line of code seems to undo that.  One could set ReconnectAtTxEnd to TRUE, but that would ping the server every time.  I am guessing that the line of code should be removed or perhaps be re-written like this:

    } finally {
        this.needsPing |= this.getReconnectAtTxEnd();   
    }
[1 Dec 2005 20:43] Mark Matthews
Alternatively, don't depend on autoReconnect, since we're deprecating it (and it has dangerous side effects when used with transactions that can never be fixed because of the way JDBC and transactions work).

You should configure your connection pool to test for and re-establish stale connections, as the only safe place to do this is outside the boundary of "real work", which the JDBC driver by itself can not determine, because it has no insight into the lifecycle of your application, other than you calling .close() on the physical connection.
[23 Feb 2006 8:29] Valeriy Kravchuk
According to the comment of Mark Matthews, this will not be fixed anyway.