[CONJ-68] java.io.IOException: Last packet not finished Created: 2013-10-10  Updated: 2015-09-15  Resolved: 2015-09-15

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.1.5
Fix Version/s: 1.3.0

Type: Bug Priority: Major
Reporter: Torsten Liermann Assignee: Rasmus Johansson (Inactive)
Resolution: Fixed Votes: 14
Labels: None
Environment:

Windows 7 64-bit, mysql 5.5.15-enterprise-commercial-advanced MySQL Enterprise Server 32 bit, glassfish 3.1.2.2. jdk 1.7


Issue Links:
Relates
relates to CONJ-34 AssertionError is thrown from PacketO... Closed
Epic Link: Load Balancing (without failover) and other MySQL options
Sprint: Sprint connector/j 1.3.0

 Description   

(Sorry, I can't speak english)

I'm trying to replace the mysql jdbc driver with mariadb jdbc driver 1.5.

In glassfish the connection pool is configured with

  • Resource Type: javax.sql.ConnectionPoolDataSource
  • Data Source Class Name: org.mariadb.jdbc.MySQLDataSource
  • user: xx
  • password: xxx
  • characterEncoding: UTF-8 (missing this in mariadb)
  • portNumber: 3306
  • serverName: localhost
  • databaseName: xxxx

Our over 400 integrations tests are running without errors with the mysql jdbc driver.
With mariadb the last 100 test fail with this exception:

```
Caused by: java.sql.SQLNonTransientConnectionException: Could not send query: Last packet not finished
at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog(MySQLStatement.java:263)
at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:287)
at org.mariadb.jdbc.MySQLStatement.executeQuery(MySQLStatement.java:301)
at org.mariadb.jdbc.MySQLPreparedStatement.executeQuery(MySQLPreparedStatement.java:112)
at com.sun.gjc.spi.jdbc40.PreparedStatementWrapper40.executeQuery(PreparedStatementWrapper40.java:642)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeSelect(DatabaseAccessor.java:931)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:607)
... 125 more
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not send query: Last packet not finished
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:975)
at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:280)
... 130 more

Caused by: java.io.IOException: Last packet not finished
at org.mariadb.jdbc.internal.common.packet.PacketOutputStream.startPacket(PacketOutputStream.java:38)
at org.mariadb.jdbc.internal.common.packet.commands.StreamedQueryPacket.send(StreamedQueryPacket.java:76)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:973)
... 131 more
```



 Comments   
Comment by Neil Wightman [ 2014-02-04 ]

I get the same problem after a while using MariaDB 10.0.7 with jdbc driver 1.1.5. (10.0.7+maria-1~raring, mariadb-java-client-1.1.5.jar)

OS = Linux mint, "Linux int0085 3.11.0-12-generic #19-Ubuntu SMP Wed Oct 9 16:20:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux"
With Apache Tomcat/7.0.47
And Java 1.7.0_51 amd64

java.io.IOException: Last packet not finished
	org.mariadb.jdbc.internal.common.packet.PacketOutputStream.startPacket(PacketOutputStream.java:38)
	org.mariadb.jdbc.internal.common.packet.commands.StreamedQueryPacket.send(StreamedQueryPacket.java:76)
	org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:973)
	org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:280)
	org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:337)
	com.intergral.fusionreactor.jdbc.StatementSurrogate.execute(StatementSurrogate.java:161)
	org.apache.tomcat.dbcp.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
	org.apache.tomcat.dbcp.dbcp.DelegatingStatement.execute(DelegatingStatement.java:264)
	org.apache.jsp.jdbc.insert_005fnow_jsp._jspService(insert_005fnow_jsp.java:119)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

Everything works fine for some time, then it starts to get this problem and I must restart tomcat.

Comment by Jason Bryan [ 2014-03-11 ]

We are seeing a similar error with 1.1.5 and 1.1.6. Here is our full stacktrace (Server version: 10.0.8-MariaDB-log Zimbra binary distribution):

2014-03-11 16:08:31,137 WARN [MailboxMove-movetest@zmb.moc:mbs2.zmb.moc] [mid=4;] mboxmove - Error occurred during restore account a89632f2-ad8c-4855-b0e2-7e730498422f
com.zimbra.common.service.ServiceException: system failure: disabling foreign key constraints
ExceptionId:MailboxMove-movetest@zmb.moc:mbs2.zmb.moc:1394568509544:d84516987e7e1948
Code:service.FAILURE
at com.zimbra.common.service.ServiceException.FAILURE(ServiceException.java:258)
at com.zimbra.cs.db.DbPool$DbConnection.enableForeignKeyConstraints(DbPool.java:104)
at com.zimbra.cs.backup.RestoreAccountSession.loadTablesFromLocalFile(RestoreAccountSession.java:969)
at com.zimbra.cs.backup.ZipBackupTarget$RestoreAcctSession.loadTables(ZipBackupTarget.java:454)
at com.zimbra.cs.backup.RestoreAccountSession.startRestore(RestoreAccountSession.java:218)
at com.zimbra.cs.backup.ZipBackupTarget.restore(ZipBackupTarget.java:172)
at com.zimbra.cs.service.backup.MoveMailbox.copyDatabase(MoveMailbox.java:1261)
at com.zimbra.cs.service.backup.MoveMailbox.moveIt(MoveMailbox.java:636)
at com.zimbra.cs.service.backup.MoveMailbox.access$100(MoveMailbox.java:92)
at com.zimbra.cs.service.backup.MoveMailbox$MailboxMoveThread.run(MoveMailbox.java:253)
Caused by: java.sql.SQLNonTransientConnectionException: Could not send query: Last packet not finished
Query is:
sql : 'SET FOREIGN_KEY_CHECKS=1'
at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog(MySQLStatement.java:263)
at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:287)
at org.mariadb.jdbc.MySQLPreparedStatement.execute(MySQLPreparedStatement.java:141)
at com.zimbra.cs.db.DebugPreparedStatement.execute(DebugPreparedStatement.java:306)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172)
at com.zimbra.cs.db.DbPool$DbConnection.enableForeignKeyConstraints(DbPool.java:102)
... 8 more
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not send query: Last packet not finished
Query is:
sql : 'SET FOREIGN_KEY_CHECKS=1'
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:975)
at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:280)
... 13 more
Caused by: java.io.IOException: Last packet not finished
at org.mariadb.jdbc.internal.common.packet.PacketOutputStream.startPacket(PacketOutputStream.java:38)
at org.mariadb.jdbc.internal.common.packet.commands.StreamedQueryPacket.send(StreamedQueryPacket.java:76)
at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:973)
... 14 more

It fails every time. Oracle's MySQL connector 5.1.29 (mysql-connector-java-5.1.29-bin.jar) succeeds without error. We only see the error with this particular operation. It seems the driver is aborting the connection prior to completion.

Comment by Quanah Gibson-Mount (Inactive) [ 2014-03-13 ]

To note, we are using MariaDB 10.0.8 as the backend, and running both the Java and DB side under Linux. This appears to be a significant bug in the MariaDB Java connector. It would be nice to know the ETA on having this fixed, since this bug has been open for over 5 months now, and makes the MariaDB Java connector unusable. Thanks!

Comment by Ivan Moucha [ 2014-03-29 ]

Hi,

i have the same issue. MariaDB 10.0.9 (win-x64), driver version 1.1.6.

Problem occurs only with pooled datasource. With simple connections (eq. jUnit) are all ok. I tested all main pooled datasource (Apache DBCP, BoneCP, C3P0) and the issue is on all three

stacktrace:

org.apache.commons.dbcp2.PoolableConnectionFactory - Failed to validate a poolable connection
java.sql.SQLNonTransientConnectionException: Could not send query: Last packet not finished
	at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136)
	at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106)
	at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog(MySQLStatement.java:263)
	at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:287)
	at org.mariadb.jdbc.MySQLStatement.executeQuery(MySQLStatement.java:301)
	at org.mariadb.jdbc.MySQLPreparedStatement.executeQuery(MySQLPreparedStatement.java:112)
	at org.apache.commons.dbcp2.PoolableConnection.validate(PoolableConnection.java:237)
	at org.apache.commons.dbcp2.PoolableConnectionFactory.validateConnection(PoolableConnectionFactory.java:303)
	at org.apache.commons.dbcp2.PoolableConnectionFactory.validateObject(PoolableConnectionFactory.java:288)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:488)
	at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:361)
	at org.apache.commons.dbcp2.PoolingDataSource.getConnection(PoolingDataSource.java:102)
	at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1413)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:280)
	at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:320)
	at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:214)
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:134)
	at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.<init>(SQLErrorCodeSQLExceptionTranslator.java:97)
	at org.mybatis.spring.MyBatisExceptionTranslator.initExceptionTranslator(MyBatisExceptionTranslator.java:85)
	at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:72)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
	at com.sun.proxy.$Proxy10.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy13.addFaceSource(Unknown Source)

Comment by Vladislav Vaintroub [ 2014-03-31 ]

So, does dbcp2 die if it cannot run validation query? The problem is mostly likely is that this connection is closed on the server side, so "last packet not finished" means that there was an IOException last time connection wrote to the socket. Why would a pool manager let invalid connection remain in the pool is a mystery.

Comment by Fredrik Vihlborg [ 2014-10-16 ]

Any update at all on this issue?

Comment by Frank Kline [ 2015-01-05 ]

same issue with mariadb connecting to mysql through dbcp2 on ubuntu 14.04 — any thoughts or workarounds?

Comment by Jason Bryan [ 2015-01-05 ]

The mysql connector works fine against mariadb and has become our workaround.

Comment by Quanah Gibson-Mount (Inactive) [ 2015-01-26 ]

Very disappointed this was not fixed in the most recent release. I would expect the MariaDB project to see this as a blocker to anyone actually being able to use this connector...

Comment by Vladislav Vaintroub [ 2015-01-27 ]

is your assumption that this s not fixed based on the actual evidence or on the fact the bug is not closed? Something that Massimo has fixed could maybe also fix this one (this commit http://bazaar.launchpad.net/~maria-captains/mariadb-java-client/trunk/revision/513) If this is the actual evidence and you exerience this in 1.1.8 would it be possible to provide a test case for that. or otherwise detailed information when this bug happens. One of the reasons such bugs are not getting fixed is absolute lack of such info.

Comment by Jason Bryan [ 2015-01-28 ]

The behavior we experienced as described in https://mariadb.atlassian.net/browse/CONJ-68?focusedCommentId=43840&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-43840 is no longer an issue for us with the 1.1.8 connector. Thank you and good work!

Comment by Georg Richter [ 2015-01-28 ]

According to Jason Bryan this bug was fixed by a prior commit and doesn't occur in 1.1.8 anymore

Comment by Momin Rashid [ 2015-04-15 ]

I am using 1.1.8 and I am experiencing this issue. After the JBoss server has been running for a while (inactive period), we start seeing the exception in the logs. It does not recover from the exception on its own, and we have to restart the JBoss to make it work again.

Our setup, mariadb server (default timeouts), ha-proxy (timeout 10 minutes), JBoss (default timeouts). My guess is that ha-proxy timesout idle connections, and the JDBC driver does not recover from that state. I can try different timeouts and make it work, however, I feel there is an issue here that should be addressed.

Comment by Rasmus Johansson (Inactive) [ 2015-04-20 ]

This bug still seems to appear for several users in cases where MySQL Connector/J works well

Comment by Diego Dupin [ 2015-07-21 ]

This kind of error is done when the connection with database has failed.
The last version 1.2.0 with failover handling must take care about this, but i will verify this.

Comment by Jason Separovic [ 2015-08-11 ]

I can confirm that this issue still exists in 1.2.0

Caused by: java.sql.SQLNonTransientConnectionException: Could not send query: Last packet not finished
	at org.mariadb.jdbc.internal.SQLExceptionMapper.get(SQLExceptionMapper.java:136) [mariadb-java-client-1.1.7.jar:]
	at org.mariadb.jdbc.internal.SQLExceptionMapper.throwException(SQLExceptionMapper.java:106) [mariadb-java-client-1.1.7.jar:]
	at org.mariadb.jdbc.MySQLStatement.executeQueryEpilog(MySQLStatement.java:264) [mariadb-java-client-1.1.7.jar:]
	at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:288) [mariadb-java-client-1.1.7.jar:]
	at org.mariadb.jdbc.MySQLStatement.executeUpdate(MySQLStatement.java:317) [mariadb-java-client-1.1.7.jar:]
	at org.mariadb.jdbc.MySQLPreparedStatement.executeUpdate(MySQLPreparedStatement.java:156) [mariadb-java-client-1.1.7.jar:]
	at org.jboss.jca.adapters.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:493)
	at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:125) [hibernate-core-4.2.0.CR1.jar:4.2.0.CR1]
	... 123 more
Caused by: org.mariadb.jdbc.internal.common.QueryException: Could not send query: Last packet not finished
	at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:1034) [mariadb-java-client-1.2.0.jar:]
	at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:1020) [mariadb-java-client-1.2.0.jar:]
	at org.mariadb.jdbc.MySQLStatement.execute(MySQLStatement.java:271) [mariadb-java-client-1.2.0.jar:]
	... 233 more
Caused by: java.io.IOException: Last packet not finished
	at org.mariadb.jdbc.internal.common.packet.PacketOutputStream.startPacket(PacketOutputStream.java:43) [mariadb-java-client-1.2.0.jar:]
	at org.mariadb.jdbc.internal.common.packet.PacketOutputStream.startPacket(PacketOutputStream.java:52) [mariadb-java-client-1.2.0.jar:]
	at org.mariadb.jdbc.internal.common.packet.commands.StreamedQueryPacket.send(StreamedQueryPacket.java:78) [mariadb-java-client-1.2.0.jar:]
	at org.mariadb.jdbc.internal.mysql.MySQLProtocol.executeQuery(MySQLProtocol.java:1029) [mariadb-java-client-1.2.0.jar:]
	... 235 more
 

I've tested 1.1.7, 1.1.8, 1.1.9 and 1.2.0, and all exhibit the same issue.

I'm using jboss 7.2.0 FInal

Here's how to reproduce:

Setup a 2 node cluster. (eg, node1, node2) - In this case I was using a 3 node percona cluster.

Here's the datasource config I used on node1. Notice the preferred host is node2 (this is important for the test)

    <datasource jndi-name="java:jboss/datasources/MySqlDS" pool-name="MySqlDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:mysql://node2:3306/mydb|jdbc:mysql://node1:3306/mydb</connection-url>
        <driver>mysql</driver>
        <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
        <url-delimiter>|</url-delimiter>
        <pool>
            <min-pool-size>10</min-pool-size>
            <max-pool-size>10</max-pool-size>
            <prefill>true</prefill>
        </pool>
        <security>
            <user-name>user</user-name>
            <password>pass</password>
        </security>
        <validation>
            <check-valid-connection-sql>select count(*) from mysql.time_zone</check-valid-connection-sql>
        </validation>
        <timeout>
            <blocking-timeout-millis>30000</blocking-timeout-millis>
            <idle-timeout-minutes>5</idle-timeout-minutes>
        </timeout>
    </datasource>
    <drivers>
        <driver name="mysql" module="org.mariadb.jdbc">
            <xa-datasource-class>org.mariadb.jdbc.MySQLDataSource</xa-datasource-class>
        </driver>
    </drivers>

Confirm that all 10 connections exist on node 2 with: mysql -e "show processlist"

Create a test table in mysql with a longtext column.

Run some test code on node1 inserting something like 10MB of random string data into the db. What you want to see here is node 1 app server writing to node 2 db, and a query that lasts long enough for you to interrupt.

Whilst the insert is happening, issue ifdown on the second node to simulate a network failure.

Expected behavior is that the jdbc connection should fail and a new connection created to node1.

What I'm actually seeing is that the connection hangs (for at least 5 minutes)

Then, when the connection is brought back on node 2, we see the "Last packet not finished error".
All subsequent inserts on node 1 fail with "Last packet not finished error".

The only way to recover is to restart JBoss on node1.

Comment by Jason Separovic [ 2015-08-11 ]

After further investigation, we found a workaround to this issue in JBoss by updating the datasource validation settings:

<validation>
      <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker"></valid-connection-checker>
      <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLExceptionSorter"></exception-sorter>
</validation>

It seems as though the default JCA connection validator has issues with this exception. However, the MySQL validator is able to detect it and throw it as an SQLException which the exception-sorter listens for.

This is from the ironjacamar user guide:

valid-connection-checker:
An org.jboss.jca.adapters.jdbc.spi.ValidConnectionChecker that provides a SQLException isValidConnection(Connection e) method to validate is a connection is valid. An exception means the connection is destroyed. This overrides the check-valid-connection-sql when present

exception-sorter:
An org.jboss.jca.adapters.jdbc.spi.ExceptionSorter that provides a boolean isExceptionFatal(SQLException e) method to validate is an exception should be broadcast to all javax.resource.spi.ConnectionEventListener as a connectionErrorOccurred message

Comment by Diego Dupin [ 2015-09-15 ]

The 1.3.0 version correct this problem, because of using a different buffer implementation.

Generated at Thu Feb 08 03:12:55 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.