Re: Connector/J "Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."
Posted by: Dean Jiang
Date: July 09, 2009 02:59AM

I encountered another problem which seems the same.

Platform: CentOS 5.0
I connect to mysql whose wait_timeout is set to 10 seconds.
Every 15 seconds, I execute a simple query, then exception goes up:

{{{
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 1 ms ago.
at sun.reflect.GeneratedConstructorAccessor4.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
at my.Jdbc.executeOne(Jdbc.java:55)
at my.Jdbc.main(Jdbc.java:18)
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2455)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2906)
... 9 more

}}}

then I close the connection with Connection.close(), establish a new connection with DriverManager.getConnection().
Interesting things appear, I check the fds with " ll /proc/<pid>/fd " and found lots of socket still open!
{{{
lrwx------ 1 root root 64 Jul 9 16:56 50 -> socket:[8250228]
lrwx------ 1 root root 64 Jul 9 16:56 51 -> socket:[8249645]
lrwx------ 1 root root 64 Jul 9 16:56 52 -> socket:[8250236]
lrwx------ 1 root root 64 Jul 9 16:56 54 -> socket:[8250292]
lrwx------ 1 root root 64 Jul 9 16:56 55 -> socket:[8249789]
lrwx------ 1 root root 64 Jul 9 16:56 56 -> socket:[8250201]
....and more....
}}}
every time the "Communications link failure" occurs, the fd count increases by 1.

I'm really shocked :(
Does anyone know why?

Options: ReplyQuote


Subject
Written By
Posted
Re: Connector/J "Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost."
July 09, 2009 02:59AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.