[CONJ-504] java.lang.ArrayIndexOutOfBoundsException when useServerPrepStmts=true Created: 2017-07-11  Updated: 2017-07-13  Resolved: 2017-07-13

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 2.0.3, 1.6.2
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Dan Assignee: Diego Dupin
Resolution: Won't Fix Votes: 0
Labels: None
Environment:

Ubuntu 17.04, mysql Ver 15.1 Distrib 10.2.6-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2, Spring Boot 2.0.0.M2, Hibernate 5.2.10.Final, HikariCP 2.6.3


Issue Links:
Problem/Incident
is caused by MDEV-13300 Query cache doesn't take in account C... Closed
Relates
relates to CONJ-491 Crossed Queries and "Packets out of o... Closed

 Description   

This was working fine until 1.5.9. All later versions seem to show this behavior.

Here is a sample stacktrace from 2.0.3.

Caused by: java.lang.ArrayIndexOutOfBoundsException: 5
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.readNextValue(SelectResultSet.java:480)
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.fetchAllResults(SelectResultSet.java:338)
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.<init>(SelectResultSet.java:211)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readResultSet(AbstractQueryProtocol.java:1315)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1078)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1028)
	at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executePreparedQuery(AbstractQueryProtocol.java:736)
	at org.mariadb.jdbc.MariaDbPreparedStatementServer.executeInternal(MariaDbPreparedStatementServer.java:370)
	at org.mariadb.jdbc.MariaDbPreparedStatementServer.execute(MariaDbPreparedStatementServer.java:333)
	at org.mariadb.jdbc.MariaDbPreparedStatementServer.executeQuery(MariaDbPreparedStatementServer.java:312)
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)



 Comments   
Comment by Diego Dupin [ 2017-07-12 ]

Hi Dan

java.lang.ArrayIndexOutOfBoundsException: 5 means that packet size is 5. The only packet that has this size is an EOF_PACKET, but for server MariaDB 10.2.6 (and MySQL > 5.7.5), EOF packet are normally not send when this flag is set, and server normally send an OK_PACKET that is bigger.
That is problably a server issue concerning EOF deprecation (CLIENT_DEPRECATE_EOF capability).

I didn't reproduced this issue for the moment.
Could you please indicate the query(ies) that throw this error and if you use any proxy (maxscale, haproxy ... ) ?

Comment by Dan [ 2017-07-12 ]

Thank you for the explanation.
The connection to mariadb is direct and doesn't use a proxy.
The query in question seems to be the last 'SELECT *'-query. This are also the first queries run, when starting the application.

Hibernate: select version0_.name as name1_16_0_, version0_.version as version2_16_0_ from version version0_ where version0_.name=?
Hibernate: select tag0_.id as id1_11_, tag0_.createdDate as createdD2_11_, tag0_.name_de as name_de3_11_, tag0_.name_ja as name_ja4_11_, tag0_.dom_content as dom_cont5_11_, tag0_.owner as owner8_11_, tag0_.superid as superid6_11_, tag0_.systype as systype7_11_ from tags tag0_ where tag0_.dom_content=? or tag0_.name_de=? or tag0_.name_ja=?
Hibernate: select user0_.id as id1_15_0_, user0_.delstatus as delstatu2_15_0_, user0_.login as login3_15_0_, user0_.password as password4_15_0_, user0_.role as role5_15_0_ from users user0_ where user0_.id=?

I will also try to build a test case, but I have trouble recreating the issue on my development machine. Maybe it's related to the production server configuration, which is frankly quite old.

Comment by Diego Dupin [ 2017-07-12 ]

I may have a hint : in this production environnement, do you query the exact same query with different drivers (different language / version) with query cache enable ?
please send the query result of :
SELECT @@have_query_cache, @@query_cache_type, @@query_cache_size ;

Comment by Diego Dupin [ 2017-07-12 ]

Reproduced.
This can lead to having 2 differents kind of error :

java.lang.ArrayIndexOutOfBoundsException: 5
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.readNextValue(SelectResultSet.java:510)
	at org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet.fetchAllResults(SelectResultSet.java:368)

or

java.sql.SQLException: (conn:28) Packets out of order when reading field packets, expected was EOF stream. Packet contents (hex) = XX

This is a bug in server cache query : MDEV-13300 has been created to handle that issue on server.
Query cache is normally disable by default. If it not, see documentation to disable it.

Comment by Dan [ 2017-07-12 ]

I think you are right. The server in question has query cache enabled.

> SELECT @@have_query_cache, @@query_cache_type, @@query_cache_size ;
+--------------------+--------------------+--------------------+
| @@have_query_cache | @@query_cache_type | @@query_cache_size |
+--------------------+--------------------+--------------------+
| YES                | ON                 |           67108864 |
+--------------------+--------------------+--------------------+
1 row in set (0.00 sec)

Thank you very much

Comment by Diego Dupin [ 2017-07-13 ]

closing since it's a server issue : this will be handled with MDEV-13300.
workaround is to disable query cache or using only drivers that have CLIENT_DEPRECATE_EOF (or driver's that haven't CLIENT_DEPRECATE_EOF)

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