Communication link failure: java.io.IOException
am 25.03.2003 16:56:00 von mysql
Hello,
We are getting this error when a new connection retrieved from the jdbc
driver is acted upon (query executed) and only after a period of inactivity
(over night). We have never encountered this in the version 2 driver.
The problem is that the driver returns an invalid connection. Looking at
the driver source code briefly, I believe there is some kind of caching of
network level objects which are not be validated before use.
Here is the stack trace:
java.sql.SQLException: Communication link failure: java.io.IOException
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1606)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:886)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:945)
at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:917)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1806)
at com.mysql.jdbc.Connection.execSQL(Connection.java:1740)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1220)
--------------------------
Eric E. Tirk, CTO
Xornet, Inc.
Tirk Internet Systems, Inc.
150 Lucius Gordon Drive
Suite 100
West Henrietta, NY 14586
--------------------------
585-454-2731
--------------------------
http://www.tirk.com
--
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe: http://lists.mysql.com/bugs?unsub=gcdmb-bugs@m.gmane.org
Re: Communication link failure: java.io.IOException
am 25.03.2003 17:31:18 von Mark Matthews
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
mysql@tirk.com wrote:
> Hello,
>
> We are getting this error when a new connection retrieved from the jdbc
> driver is acted upon (query executed) and only after a period of inactivity
> (over night). We have never encountered this in the version 2 driver.
>
> The problem is that the driver returns an invalid connection. Looking at
> the driver source code briefly, I believe there is some kind of caching of
> network level objects which are not be validated before use.
>
> Here is the stack trace:
>
> java.sql.SQLException: Communication link failure: java.io.IOException
> at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1606)
> at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:886)
> at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:945)
> at com.mysql.jdbc.MysqlIO.sqlQuery(MysqlIO.java:917)
> at com.mysql.jdbc.Connection.execSQL(Connection.java:1806)
> at com.mysql.jdbc.Connection.execSQL(Connection.java:1740)
> at com.mysql.jdbc.Statement.executeQuery(Statement.java:1220)
Are you using 'autoReconnect=true'? If so, have you looked at the README
for 3.0.x that states that its behavior has changed:
> The driver now has fail-over support. This allows the driver to fail-over to any number
> of "slave" hosts and still perform read-only queries. Fail-over only happens when the
> connection is in a autoCommit(true) state, because fail-over can not happen reliably
> when a transaction is in progress. Most good application servers and connection pools
> set autoCommit to 'true' at the end of every transaction/connection use.
>
> The fail-over functionality has the following behavior:
>
> If the URL parameter "autoReconnect" is false:
>
> Failover only happens at connection initialization, and failback occurs
> when the driver determines that the first host has become available again
MySQL does close connections after a period of inactivity, and a range
of solutions for dealing with this are in the README that comes with the
driver in the trouble shooting section:
> Issue:
>
> "I have a servlet/application that works fine for a day, and then stops
> working overnight".
>
> Resolution:
>
> MySQL closes connections after 8 hours of inactivity. You either
> need to use a connection pool that handles stale connections or use the
> "autoReconnect" parameter (see "USAGE AND INSTALLATION"). Also, you should
> be catching SQLExceptions in your application and dealing with them, rather
> than propagating them all the way until your application exits, this is just
> good software development. MySQL Connector/J will set the SQLState (see
> java.sql.SQLException.getSQLState() in your APIDOCS) to "08S01" when it
> encounters network-connectivity issues during the processing of a query.
> Your application code should then attempt to re-connect to MySQL at this
> point.
Given the stack trace above, the driver is not 'returning an invalid
connection', you have a connection which has gone 'stale'. It is not the
responsibility of the driver to ensure that a connection is valid before
executing a query (it is the driver's responsibility when it _creates_ a
connection, but this is not the case here). It is the responsibility of
the application to either handle the case when a connection goes stale
(look at any decent connection pooling implementation, for example), or
to ensure that the connection is valid before attempting to use it (once
again, see any decent connection pooling implementation). Connector/J
does have the 'autoReconnect' property, which will take care of this for
you, but it has caveats, and using it is no excuse for proper
application design.
-Mark
- --
MySQL 2003 Users Conference -> http://www.mysql.com/events/uc2003/
For technical support contracts, visit https://order.mysql.com/?ref=mmma
__ ___ ___ ____ __
/ |/ /_ __/ __/ __ \/ / Mark Matthews
/ /|_/ / // /\ \/ /_/ / /__ MySQL AB, Full-Time Developer - JDBC/Java
/_/ /_/\_, /___/\___\_\___/ Flossmoor (Chicago), IL USA
<___/ www.mysql.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.1.90 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE+gIRbtvXNTca6JD8RAvIJAKCTIx75qE6tnm2sL+YlV5iML5i5CACb BPNY
019usHVIExoZSgRzYCpyJpw=
=j58w
-----END PGP SIGNATURE-----
--
MySQL Bugs Mailing List
For list archives: http://lists.mysql.com/bugs
To unsubscribe: http://lists.mysql.com/bugs?unsub=gcdmb-bugs@m.gmane.org