Type:
Bug
Priority:
Major
Resolution:
Fixed
Affects Version/s:
2.7.7
When as a non-SUPER user calling a stored procedure with a DEFINER having full privileges and DEFINER security context no timeout happens when using CallableStatement with setQueryTimeout set.
It is only this combination that leads to no timeout being triggered.
If the connection user has full privileges: times out just fine
If the procedure has a non-full priv. definer, or INVOKER security context: times out just fine
Using regular Statment instead of CallableStatement: times out just fine
C/J 3.x instead of 2.7.x: times out just fine.
How to reproduce:
SQL setup
CREATE USER user @localhost IDENTIFIED BY 'Secret23!' ;
GRANT ALL ON test.* TO user @localhost;
DELIMITER //
CREATE DEFINER=root@localhost PROCEDURE p_r_d() SQL SECURITY DEFINER
BEGIN
SELECT SLEEP(60), "hello" ;
END ;
//
CREATE DEFINER=root@localhost PROCEDURE p_r_i() SQL SECURITY INVOKER
BEGIN
SELECT SLEEP(60), "hello" ;
END ;
//
CREATE DEFINER= user @localhost PROCEDURE p_u_d() SQL SECURITY DEFINER
BEGIN
SELECT SLEEP(60), "hello" ;
END ;
//
CREATE DEFINER= user @localhost PROCEDURE p_u_i() SQL SECURITY INVOKER
BEGIN
SELECT SLEEP(60), "hello" ;
END ;
//
DELIMITER ;
Java test code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class CS0492599 {
public static void run_query(String title, String query, String connect_url) {
System.out.print(title);
System.out.print( " -> " );
try {
Connection con = DriverManager.getConnection(connect_url);
Statement st = con.createStatement();
st.setQueryTimeout( 10 );
ResultSet rs = st.executeQuery(query);
while (rs.next()) {
System.out.print(rs.getString( 1 ));
System.out.print( ": " );
System.out.println(rs.getString( 2 ));
}
con.close();
System.out.println();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public static void run_callable(String title, String query, String connect_url) {
System.out.print(title);
System.out.print( " -> " );
try {
Connection con = DriverManager.getConnection(connect_url);
CallableStatement st = con.prepareCall(query);
st.setQueryTimeout( 10 );
boolean rs = st.execute();
if (rs) {
System.out.print( "success" );
} else {
System.out.print( "fail" );
}
con.close();
System.out.println();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
public static void main(String[] args){
String connect_url = "jdbc:mariadb://localhost/test"
+ "?user=user"
+ "&password=Secret23!" ;
System.out.println( "using Statement:" );
run_query( "root, definer" , "CALL p_r_d;" , connect_url);
run_query( "root, invoker" , "CALL p_r_i;" , connect_url);
run_query( "user, definer" , "CALL p_u_d;" , connect_url);
run_query( "user, invoker" , "CALL p_u_i;" , connect_url);
System.out.println( "using CallableStatement:" );
run_callable( "root, definer" , "CALL p_r_d;" , connect_url);
run_callable( "root, invoker" , "CALL p_r_i;" , connect_url);
run_callable( "user, definer" , "CALL p_u_d;" , connect_url);
run_callable( "user, invoker" , "CALL p_u_i;" , connect_url);
}
}
Using 2.7.7 this leads to:
using Statement:
root, definer -> (conn=52) Query execution was interrupted (max_statement_time exceeded)
root, invoker -> (conn=53) Query execution was interrupted (max_statement_time exceeded)
user, definer -> (conn=54) Query execution was interrupted (max_statement_time exceeded)
user, invoker -> (conn=55) Query execution was interrupted (max_statement_time exceeded)
using CallableStatement:
root, definer -> success
root, invoker -> (conn=58) Query timed out
user, definer -> (conn=60) Query timed out
user, invoker -> (conn=62) Query timed out
Using 3.0.9 or 3.1.0:
using Statement:
root, definer -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=64) Query execution was interrupted (max_statement_time exceeded)
root, invoker -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=65) Query execution was interrupted (max_statement_time exceeded)
user, definer -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=66) Query execution was interrupted (max_statement_time exceeded)
user, invoker -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=67) Query execution was interrupted (max_statement_time exceeded)
using CallableStatement:
root, definer -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=68) Query execution was interrupted (max_statement_time exceeded)
root, invoker -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=69) Query execution was interrupted (max_statement_time exceeded)
user, definer -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=70) Query execution was interrupted (max_statement_time exceeded)
user, invoker -> [ WARN] (main) Error: 1969-70100: Query execution was interrupted (max_statement_time exceeded)
(conn=71) Query execution was interrupted (max_statement_time exceeded)
{"report":{"fcp":884.0999999046326,"ttfb":244.89999985694885,"pageVisibility":"visible","entityId":118127,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"11cb48c8-74bf-4a66-8d5e-7731f3e02361","navigationType":0,"readyForUser":998.3999998569489,"redirectCount":0,"resourceLoadedEnd":934.7999999523163,"resourceLoadedStart":249.69999980926514,"resourceTiming":[{"duration":6.400000095367432,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":249.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":249.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":256.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":6.200000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":250.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":250.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":256.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":135.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":250.19999980926514,"connectEnd":250.19999980926514,"connectStart":250.19999980926514,"domainLookupEnd":250.19999980926514,"domainLookupStart":250.19999980926514,"fetchStart":250.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":250.19999980926514,"responseEnd":386,"responseStart":386,"secureConnectionStart":250.19999980926514},{"duration":111.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":250.39999985694885,"connectEnd":250.39999985694885,"connectStart":250.39999985694885,"domainLookupEnd":250.39999985694885,"domainLookupStart":250.39999985694885,"fetchStart":250.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":250.39999985694885,"responseEnd":362.19999980926514,"responseStart":362.19999980926514,"secureConnectionStart":250.39999985694885},{"duration":10.700000047683716,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":250.59999990463257,"connectEnd":250.59999990463257,"connectStart":250.59999990463257,"domainLookupEnd":250.59999990463257,"domainLookupStart":250.59999990463257,"fetchStart":250.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":250.59999990463257,"responseEnd":261.2999999523163,"responseStart":261.2999999523163,"secureConnectionStart":250.59999990463257},{"duration":115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":250.79999995231628,"connectEnd":250.79999995231628,"connectStart":250.79999995231628,"domainLookupEnd":250.79999995231628,"domainLookupStart":250.79999995231628,"fetchStart":250.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":250.79999995231628,"responseEnd":365.7999999523163,"responseStart":365.7999999523163,"secureConnectionStart":250.79999995231628},{"duration":115.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":251,"connectEnd":251,"connectStart":251,"domainLookupEnd":251,"domainLookupStart":251,"fetchStart":251,"redirectEnd":0,"redirectStart":0,"requestStart":251,"responseEnd":366.09999990463257,"responseStart":366.09999990463257,"secureConnectionStart":251},{"duration":116.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":251.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":367.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":136.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":251.29999995231628,"connectEnd":251.29999995231628,"connectStart":251.29999995231628,"domainLookupEnd":251.29999995231628,"domainLookupStart":251.29999995231628,"fetchStart":251.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":251.29999995231628,"responseEnd":387.7999999523163,"responseStart":387.69999980926514,"secureConnectionStart":251.29999995231628},{"duration":137.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":251.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":388.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":136.79999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":251.59999990463257,"connectEnd":251.59999990463257,"connectStart":251.59999990463257,"domainLookupEnd":251.59999990463257,"domainLookupStart":251.59999990463257,"fetchStart":251.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":251.59999990463257,"responseEnd":388.39999985694885,"responseStart":388.39999985694885,"secureConnectionStart":251.59999990463257},{"duration":286.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":282.59999990463257,"connectEnd":282.59999990463257,"connectStart":282.59999990463257,"domainLookupEnd":282.59999990463257,"domainLookupStart":282.59999990463257,"fetchStart":282.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":282.59999990463257,"responseEnd":568.8999998569489,"responseStart":568.8999998569489,"secureConnectionStart":282.59999990463257},{"duration":589.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":282.59999990463257,"connectEnd":282.59999990463257,"connectStart":282.59999990463257,"domainLookupEnd":282.59999990463257,"domainLookupStart":282.59999990463257,"fetchStart":282.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":282.59999990463257,"responseEnd":872.5,"responseStart":872.5,"secureConnectionStart":282.59999990463257},{"duration":160.60000014305115,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":605.6999998092651,"connectEnd":605.6999998092651,"connectStart":605.6999998092651,"domainLookupEnd":605.6999998092651,"domainLookupStart":605.6999998092651,"fetchStart":605.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":605.6999998092651,"responseEnd":766.2999999523163,"responseStart":766.2999999523163,"secureConnectionStart":605.6999998092651},{"duration":102.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":832.6999998092651,"connectEnd":832.6999998092651,"connectStart":832.6999998092651,"domainLookupEnd":832.6999998092651,"domainLookupStart":832.6999998092651,"fetchStart":832.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":832.6999998092651,"responseEnd":934.7999999523163,"responseStart":934.7999999523163,"secureConnectionStart":832.6999998092651},{"duration":177.29999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":876,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":876,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1053.2999999523163,"responseStart":0,"secureConnectionStart":0}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":43,"responseStart":245,"responseEnd":282,"domLoading":249,"domInteractive":1082,"domContentLoadedEventStart":1082,"domContentLoadedEventEnd":1130,"domComplete":1327,"loadEventStart":1327,"loadEventEnd":1327,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1055.3999998569489},{"name":"bigPipe.sidebar-id.end","time":1056.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1056.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1057.8999998569489},{"name":"activityTabFullyLoaded","time":1150}],"measures":[],"correlationId":"9f9422df66d05f","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":10,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Query Timeout are handle this way :
When using CallableStatement, underlying, connector use server side prepare statement, in order to retrieve output parameters if any.
The thing is that 3.x is a complete rewrite, and server side prepared statement now use pipelining and assume prepare command will succeed (expect server > 10.6 - if not the case, it still will work, but will be a little less performant). That permits to use "SET STATEMENT max_statement_time=XXX FOR <command>" easily
in 2.x, that's different, PREPARE command is immedialty executed when creating CallableStatement, not assuming that PREPARE won't fails. setQueryTimeout() can only be set after CallableStatement creation, so that would means closing previous PREPARE and re-PREPARE with "SET STATEMENT max_statement_time=XXX FOR" prefix.
So current implementation is having an internal timeout, that when reaching timeout will executes a "KILL QUERY XX" statement on another connection.
The problem in this specific case is that the command "KILL QUERY xx" ends with an error "You are not the owner of thread xx".
CALL statement can be prepared without issue. So specifically when using CallableStatement, connector can work partially the same way than 3.0, solving this problem.