Bug #72394 Connector/J should raise MySQLTimeoutException by MAX_STATEMENT_TIME
Submitted: 20 Apr 2014 8:35 Modified: 23 Apr 2014 7:43
Reporter: Sadao Hiratsuka Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.1.30 OS:Any
Assigned to: Alexander Soklakov CPU Architecture:Any
Tags: max_statement_time

[20 Apr 2014 8:35] Sadao Hiratsuka
Description:
When setQueryTimeout() is called and timeout happens, Connector/J raises MySQLTimeoutException.
But when MAX_STATEMENT_TIME (introduced by MySQL 5.7.4) is set and timeout happens, Connector/J raises SQLException only.

How to repeat:
- MAX_STATEMENT_TIME
java.sql.SQLException: Query execution was interrupted, max_statement_time exceeded
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4232)
	at com.mysql.jdbc.MysqlIO.nextRowFast(MysqlIO.java:2188)
	at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:2044)
	at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3549)
	at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:489)
	at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3240)
	at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2411)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2834)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
	at jdbc.Timeout.main(Timeout.java:19)

- setQueryTimeout
com.mysql.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or client request
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2966)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2838)
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2212)
	at jdbc.Timeout.main(Timeout.java:22)

Suggested fix:
setQueryTimeout() sets StatementImpl.wasCancelled as true,
so I think MAX_STATEMENT_TIME should do it,
or SQLError#createSQLException should handle this flag.
[23 Apr 2014 7:43] Alexander Soklakov
Hi Sadao,

Thank you for this report. We'll try to implement this as part as 5.7.4 support, however I can't say right now is it possible.