[CONJ-270] BufferOverflowException Created: 2016-03-26  Updated: 2016-04-04  Resolved: 2016-04-04

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.3.6
Fix Version/s: 1.4.1

Type: Bug Priority: Major
Reporter: Piotr Blasiak Assignee: Diego Dupin
Resolution: Fixed Votes: 1
Labels: None
Environment:

Tomcat7



 Description   

The exact same query works nicely in the mysql connector, but with the mariadb one it gives me an exception. It´s a relatively large query & result set.

Kind of difficult to reproduce outside of my production environment but maybe this stacktrace is enough?

at org.hibernate.jpa.criteria.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:67)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1300)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:236)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:497)
at org.hibernate.loader.Loader.list(Loader.java:2365)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2370)
at org.hibernate.loader.Loader.doList(Loader.java:2540)
at org.hibernate.loader.Loader.doList(Loader.java:2554)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:355)
at org.hibernate.loader.Loader.doQuery(Loader.java:910)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1839)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1863)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2066)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:82)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.executeQuery(MariaDbServerPreparedStatement.java:341)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.execute(MariaDbServerPreparedStatement.java:369)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.executeInternal(MariaDbServerPreparedStatement.java:279)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executePreparedQuery(AbstractQueryProtocol.java:578)
at org.mariadb.jdbc.internal.packet.send.SendExecutePrepareStatementPacket.send(SendExecutePrepareStatementPacket.java:105)
at java.nio.ByteBuffer.put(ByteBuffer.java:859)
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:189)



 Comments   
Comment by Diego Dupin [ 2016-03-30 ]

Hi,

The stacktrace permit to have some indications, but not the detail.
Could you please execute this query "SELECT @@max_allowed_packet" and your connection string url if this value is changed.
That must be enought to identify the problem.

Comment by Piotr Blasiak [ 2016-03-30 ]

That query returns the number 4194304 and my connection string is nothing out of the ordinary: jdbc:mysql://hostname:3306/dbname

Comment by Christian Bourque [ 2016-03-31 ]

Same problem here!

Caused by: java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:183)
at java.nio.ByteBuffer.put(ByteBuffer.java:832)
at org.mariadb.jdbc.internal.packet.send.SendExecutePrepareStatementPacket.send(SendExecutePrepareStatementPacket.java:105)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executePreparedQuery(AbstractQueryProtocol.java:578)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.executeInternal(MariaDbServerPreparedStatement.java:279)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.execute(MariaDbServerPreparedStatement.java:369)
at org.mariadb.jdbc.MariaDbServerPreparedStatement.executeQuery(MariaDbServerPreparedStatement.java:341)
at com.zaxxer.hikari.proxy.PreparedStatementProxy.executeQuery(PreparedStatementProxy.java:52)
at com.zaxxer.hikari.proxy.HikariPreparedStatementProxy.executeQuery(HikariPreparedStatementProxy.java)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
at org.hibernate.loader.Loader.getResultSet(Loader.java:2065)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1862)
at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1838)
at org.hibernate.loader.Loader.doQuery(Loader.java:909)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2553)
at org.hibernate.loader.Loader.doList(Loader.java:2539)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
at org.hibernate.loader.Loader.list(Loader.java:2364)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:231)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1264)
at org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:573)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:449)

Comment by Diego Dupin [ 2016-04-04 ]

Reading code, I only see a possible problem is a prepared query has more than 8192 parameters (32768 for version >= 1.3.7).
I can reproduced this with this test :

    @Test
    public void testRewriteMultiPacket() throws SQLException {
        createTable("PreparedStatementTest3", "id int");
        String sql = "INSERT INTO PreparedStatementTest3 VALUES (?)";
        for (int i = 1 ; i < 8 * 1024 ; i++) {
            sql += ",(?)";
        }
        PreparedStatement pstmt = sharedConnection.prepareStatement(sql);
        for (int i = 1; i < 8 * 1024 + 1; i++) {
            pstmt.setInt(i, i);
        }
        pstmt.execute();
    }

Can you confirm that your query has so much parameters ?

This will be fixed in 1.4.1.

Comment by Diego Dupin [ 2016-04-04 ]

Driver will permit 65536 parameters now (max possible value)

commit : https://github.com/MariaDB/mariadb-connector-j/commit/171b1abda8d72d44c599f3d5dbb30d55ec8ce022

Snapshot with correction available through maven :

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <name>Sonatype Nexus Snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>org.mariadb.jdbc</groupId>
        <artifactId>mariadb-java-client</artifactId>
        <version>1.4.1-SNAPSHOT</version>
    </dependency>
</dependencies>

Comment by Christian Bourque [ 2016-04-04 ]

Yes, I confirm that our query has more than 8192 parameters (we have a lot of "or in (?, ?, ?, ...)" in the same query)!

Comment by Diego Dupin [ 2016-04-04 ]

Thanks for the confirmation.

Correction 1.4.1 which contain the correction will be released by the end of the week.

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