Bug #27284 Error when opening connection for creating temporary tables
Submitted: 20 Mar 2007 11:00 Modified: 17 Apr 2007 18:05
Reporter: Stephane Giron Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: Mark Matthews CPU Architecture:Any

[20 Mar 2007 11:00] Stephane Giron
Description:
If I do a simple test that loops :

- get a new connection
- create a statement
- create a temporary table using this statement
- close the statement
- close the connection

I get an error quite quickly using either 5.0.5 or 3.1.14 drivers.
The error is : 

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception: 

** BEGIN NESTED EXCEPTION ** 

java.net.SocketException
MESSAGE: Connection reset

STACKTRACE:

java.net.SocketException: Connection reset
	at java.net.SocketInputStream.read(SocketInputStream.java:168)
	at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
	at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
	at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1931)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2380)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2909)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
	at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2361)
	at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3748)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2585)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(DriverManager.java:512)
	at java.sql.DriverManager.getConnection(DriverManager.java:171)

...
...

** END NESTED EXCEPTION **

Last packet sent to the server was 23 ms ago.
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2592)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2909)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695)
	at com.mysql.jdbc.Connection.execSQL(Connection.java:3020)
	at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2361)
	at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3748)
	at com.mysql.jdbc.Connection.createNewIO(Connection.java:2585)
	at com.mysql.jdbc.Connection.<init>(Connection.java:1485)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
	at java.sql.DriverManager.getConnection(DriverManager.java:512)
	at java.sql.DriverManager.getConnection(DriverManager.java:171)

...
...
Broken in 9 steps...

Note that if I try other statements, such as :
stmt.executeUpdate("CREATE TABLE foo (i int)");
stmt.executeUpdate("DROP TABLE foo");

the test does not break.

How to repeat:
Just run the provided test case :

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import junit.framework.TestCase;

public class MyTest extends TestCase
{
  /**
   * @see junit.framework.TestCase#setUp()
   */
  protected void setUp() throws Exception
  {
    Class.forName("com.mysql.jdbc.Driver");

  }

  /**
   * @see junit.framework.TestCase#tearDown()
   */
  protected void tearDown() throws Exception
  {
  }

  

  public void testMySQLConnection() throws
      SQLException, InterruptedException
  {
    Connection connection = null;
    int i = 0;
    try
    {
      for (i = 0; i < 1000; i++)
      {
        connection = getConnection();
        Statement stmt = connection.createStatement();
        stmt.executeUpdate("CREATE TEMPORARY TABLE foo (i int)");
//        stmt.executeUpdate("CREATE TABLE foo (i int)");
//        stmt.executeUpdate("DROP TABLE foo");

        stmt.close();
        connection.close();
      }
    }
    catch (Exception e)
    {
      e.printStackTrace();
      Thread.sleep(1000);
      System.out.println("Broken in " + i + " steps...");
      fail();
    }

  }

  private Connection getConnection() throws SQLException
  {
    return DriverManager.getConnection("jdbc:mysql://myServer/db1", "myUser",
        "myPass");
  }

}
[20 Mar 2007 18:11] Mark Matthews
I can't repeat this with C/J 5.0 and MySQL-4.0, 4.1, 5.0 and 5.1.

What version of the server are you running, and on what platform? Are you sure it's not the server crashing and restarting (check your error logs).
[17 Apr 2007 18:05] Stephane Giron
Hi,

Thank you for your answer and sorry for my own late answer.
As a matter of fact, this seems to be related to a server crash.

I tested it against mysql 5.0.24 on RHEL4, on different hosts (all with same OS/mysql version) and it seems to reproduce on all.

I will try to test it against mysql 5.0.22 on RHEL5.

Cheers

Stephane
[15 May 2007 14:28] Tonci Grgin
Stefan, please reopen the report after you do your testing.