Bug #115781 stored procedure with cursor reading (useCursorFetch=true) hang
Submitted: 6 Aug 2024 8:59 Modified: 6 Aug 2024 9:37
Reporter: DF Rong Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:Connector/J 8.0.25 OS:Any
Assigned to: MySQL Verification Team CPU Architecture:Any
Tags: useCursorFetch

[6 Aug 2024 8:59] DF Rong
Description:
When using MySQL JDBC to execute a stored procedure with cursor reading (useCursorFetch=true, fetchsize>0), if there is an unexpected exception within the stored procedure, the JDBC will not throw an error and instead hang indefinitely. However, in normal mode and streaming mode, the exceptions in the stored procedure are timely thrown (assuming there is no specified exception-handling syntax within the stored procedure).

How to repeat:
java.io.File;lportmport java.util.ArrayList;mport java.util.Calendar;mport java.util.List;mport java.util.Date;
mport java.sql.*;mport java.text .SimpleDateFormat;
ublic class Test [
public static void main(String args[]) throws ExceptionfSimpleDateFormat formater = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss .SSs");String jdbc_type = args[o];String ip = args[1];String port = args[2];String user = args[3];String pass = args[4];String db = args[5];
if(jdbc_type.equals("57"))[Class.forName("com.mysql.jdbc.Driver"); else {Class.forName("com.mysql.cj.jdbc.Driver");
System.out ,printIn(formater .format(new Date(System.currentTimeMillis())) + " jdbc_type: "+jdbc type)!
String url = "jdbc:mysql://" + ip +“:" + port +“/" + db +?useSSL=false&useCursorFetch=true&useServerPrepStmts=true";System.out.printIn(formater,format(new DateSystem,currentTimeMillis())) + " url: " + url);
Connection conn1 = null;PreparedStatement stmt = null ;
ResultSet rs = null;
try lSystem.out.println(formater,format(new Date(System,currentTimeMillis())) + " connecting ...");conn1 = DriverManager .getConnection(url, user, pass);System.out,println(formater,format(new Date(System. currentTimeMillis())) + " connected")stmt = conn1.prepareStatement("select 1 fromdual where 1=(select1 as a union all select 2)")stmt.setFetchSize(100);System.err.println(formater.format(new Date(System. currentTimeMillis())) + " query ...");rs = stmt .executeQuery();] catch (Exception e) 
e.printStackTrace();finally (if(null!=rs){try{rs.close();}catch (Exception ignore) [}
System.err.printIn(formater .format(new Date(System.currentTimeMillis()))+
+ e.getMessage());
if(null!=stmt){try{stmt.close();}catch (Exception ignore)[}
if(null!=conn1){try{conn1.close();}catch (Exception ignore) 

Suggested fix:
Report errors in time
[6 Aug 2024 9:37] MySQL Verification Team
Hi Mr. Rong,

Thank you for your bug report.

However, release  8.0.25 is years old and is not maintained any more.

Hence, please try using our 8.0.39 server and 8.0.39 Connector/J/

Unsupported.