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

No timeout exception on query with sleep(50) and querytimeout(1)

Details

    Description

      I try to create a timeout exception with the current mariadb connector.
      For this i create a select statement with the sleep value of 50 seconds but a querytimeout value of 1.

      the query runs all the 50 seconds and has a return value - see log information "has next"

      Is the handling from my side correct?

      final String sql = "SELECT sleep(50)";
       
      	        try (final PreparedStatement preparedStatement = dbCon.getPreparedStatement(sql)) {
      	            logger.info("### Prepared Statement: " + preparedStatement);
       
      	            preparedStatement.setQueryTimeout(1);
      	            final ResultSet rowset = preparedStatement.executeQuery();
      	            logger.info("### Finsih Statement: " + rowset.toString());
      	            logger.info("### Has next: " + rowset.next());
      	        } catch (final Exception e) {
      	            logger.severe(e.getMessage());
      	        }
      	        
      	        try (final Statement statement = dbCon.getStatement()) {
      	            logger.info("### Statement: " + statement );
       
      	            statement .setQueryTimeout(1);
      	            final ResultSet rowset = statement .executeQuery(sql);
      	            logger.info("### Finsih Statement: " + rowset.toString());
      	            logger.info("### Has next: " + rowset.next());
      	        } catch (final Exception e) {
      	            logger.severe(e.getMessage());
      	        }
      

      Jun 02, 2017 9:42:48 AM com.mariadb.conj.QueryTimeoutIssue selectEntry
      INFORMATION: ### Prepared Statement: sql : 'SELECT sleep(50)', parameters : []
      Jun 02, 2017 9:43:38 AM com.mariadb.conj.QueryTimeoutIssue selectEntry
      INFORMATION: ### Finsih Statement: org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet@4629104a
      Jun 02, 2017 9:43:38 AM com.mariadb.conj.QueryTimeoutIssue selectEntry
      INFORMATION: ### Has next: true
      Jun 02, 2017 9:43:38 AM com.mariadb.conj.QueryTimeoutIssue selectEntry
      INFORMATION: ### Statement: org.mariadb.jdbc.MariaDbStatement@27f8302d
      Jun 02, 2017 9:43:39 AM com.mariadb.conj.QueryTimeoutIssue selectEntry
      INFORMATION: ### Finsih Statement: org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet@4d76f3f8
      Jun 02, 2017 9:43:39 AM com.mariadb.conj.QueryTimeoutIssue selectEntry
      INFORMATION: ### Has next: true
      

      Attachments

        Activity

          fahrenholz sfahren created issue -
          fahrenholz sfahren made changes -
          Field Original Value New Value
          Summary No timeout exception on query with sleep(5) and querytimeout(1) No timeout exception on query with sleep(50) and querytimeout(1)
          diego dupin Diego Dupin added a comment -

          Your tests are corrects, but SLEEP has a specificity : see documentation : If SLEEP() is interrupted, it returns 1, not an exception.
          In fact, you can use all command but sleep ...

          diego dupin Diego Dupin added a comment - Your tests are corrects, but SLEEP has a specificity : see documentation : If SLEEP() is interrupted, it returns 1, not an exception. In fact, you can use all command but sleep ...
          diego dupin Diego Dupin added a comment -

          Sorry, i read text too quickly, it seems that PrepareStatement setReadonly doesn't take in account setTimeout ?!
          checking now

          diego dupin Diego Dupin added a comment - Sorry, i read text too quickly, it seems that PrepareStatement setReadonly doesn't take in account setTimeout ?! checking now
          fahrenholz sfahren added a comment -

          Thank you for the fast answer.
          I tested with another database and get the correct exception:

          class java.sql.SQLTimeoutException | (conn:80) (conn:80) Query execution was interrupted (max_statement_time exceeded)

          What i also see was that the exception is only throw from Statement not from PreparedStatement.. (140MB table with 1.1 million entries, no indizies..)
          Sorry for the request! Thank you very much for the help

          fahrenholz sfahren added a comment - Thank you for the fast answer. I tested with another database and get the correct exception: class java.sql.SQLTimeoutException | (conn:80) (conn:80) Query execution was interrupted (max_statement_time exceeded) What i also see was that the exception is only throw from Statement not from PreparedStatement.. (140MB table with 1.1 million entries, no indizies..) Sorry for the request! Thank you very much for the help
          diego dupin Diego Dupin made changes -
          Fix Version/s 1.6.1 [ 22550 ]
          Fix Version/s 2.0.2 [ 22551 ]
          diego dupin Diego Dupin made changes -
          Component/s JDBC 4.2 compatibility [ 14001 ]
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 81061 ] MariaDB v4 [ 134992 ]

          People

            diego dupin Diego Dupin
            fahrenholz sfahren
            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.