Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-873

IndexOutOfBoundsException when executing prepared queries using automatic key generation in parallel

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 2.7.2
    • 2.7.4
    • Other
    • None

    Description

      We found an issue when executing prepared queries using automatic key generation in parallel. It occurs when accessing a MySQL database (tested with 8.0.16, 5.7.26 and 5.6.50) via MariaDB Connector/J (2.7.2). When executing the following piece of code multiple times in parallel:

      try (
          Connection connection = DriverManager.getConnection("jdbc:mysql://ensembldb.ensembl.org:3306?pool=true&minPoolSize=1&maxPoolSize=5&maxIdleTime=60", "anonymous", "");
          PreparedStatement statement = connection.prepareStatement("SELECT * FROM acanthochromis_polyacanthus_core_100_1.analysis WHERE analysis_id = ?", Statement.RETURN_GENERATED_KEYS)
      ) {
          statement.setInt(1, 5);
          try (ResultSet result = statement.executeQuery()) {
              try (ResultSet keys = statement.getGeneratedKeys()) {
                  ResultSetMetaData metadata = keys.getMetaData();
                  int cols = metadata.getColumnCount();
                  for (int i = 1; i <= cols; i++)
                      metadata.getColumnLabel(i);
              }
          }
      }
      

      we see the following exceptions:

      java.lang.ArrayIndexOutOfBoundsException: 38
      	at org.mariadb.jdbc.internal.com.read.Buffer.skipLengthEncodedBytes(Buffer.java:228)
      	at org.mariadb.jdbc.internal.com.read.resultset.ColumnDefinition.getString(ColumnDefinition.java:225)
      	at org.mariadb.jdbc.internal.com.read.resultset.ColumnDefinition.getName(ColumnDefinition.java:243)
      	at org.mariadb.jdbc.MariaDbResultSetMetaData.getColumnLabel(MariaDbResultSetMetaData.java:154)
      	at MariaDBConnectionPool.executeQuery(MariaDBConnectionPool.java:30)
      	[...]
      

      java.lang.StringIndexOutOfBoundsException: String index out of range: 121
      	at java.lang.String.checkBounds(String.java:385)
      	at java.lang.String.<init>(String.java:462)
      	at org.mariadb.jdbc.internal.com.read.Buffer.readStringLengthEncoded(Buffer.java:123)
      	at org.mariadb.jdbc.internal.com.read.resultset.ColumnDefinition.getString(ColumnDefinition.java:227)
      	at org.mariadb.jdbc.internal.com.read.resultset.ColumnDefinition.getName(ColumnDefinition.java:243)
      	at org.mariadb.jdbc.MariaDbResultSetMetaData.getColumnLabel(MariaDbResultSetMetaData.java:154)
      	at MariaDBConnectionPool.executeQuery(MariaDBConnectionPool.java:30)
      	[...]
      

      A reproducer can be found at https://github.com/riemenschneider/JDBCPoolUsingMariaDBDriverTest. It contains the relevant test:

      • MariaDBConnectionPool: using the connection pooling provided by MariaDB Connector/J for running 1000 prepared queries in parallel.

      Ignore the remaining tests. These were just used for tracking the issue down to MariaDB Connector/J.

      Steps to reproduce:

      1. Clone the reproducer.
      2. Run gradlew clean test --tests MariaDBConnectionPool in the root folder of the cloned reproducer.

      Attachments

        1. ddl.sql
          8 kB
        2. test.zip
          19 kB

        Activity

          People

            diego dupin Diego Dupin
            tori Tobias Riemenschneider
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.