Bug #75309 mysql connector/J driver in streaming mode will in the blocking state
Submitted: 25 Dec 2014 9:41 Modified: 10 Feb 2015 17:42
Reporter: agapple wu Email Updates:
Status: Closed Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:5.1.34 OS:MacOS
Assigned to: Filipe Silva CPU Architecture:Any

[25 Dec 2014 9:41] agapple wu
mysql connector/J driver in streaming mode will in the blocking state and not return. 

Connection conn = DriverManager.getConnection("jdbc:mysql://", "root", "hello");
Statement st = conn.createStatement();
st.setFetchSize(Integer.MIN_VALUE); // import
ResultSet rs = null;
try {
    rs = st.executeQuery("select 1+18446744073709551615");
} catch (Throwable e) {
    e.printStackTrace();//  com.mysql.jdbc.MysqlDataTruncation: Data truncation: BIGINT UNSIGNED value is out of range in '(1 + 18446744073709551615)'
    rs.close(); // will block 

rs.close() method will in the blocking state (wait for RowDataDynamic.nextRecord() )
execute sql is fine in non-streaming mode.
java stack.

"main" prio=5 tid=0x00007fa73c00c800 nid=0x1903 runnable [0x0000000110b1e000]
   java.lang.Thread.State: RUNNABLE
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:152)
	at java.net.SocketInputStream.read(SocketInputStream.java:122)
	at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:100)
	at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:143)
	at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:173)
	- locked <0x00000007d6086880> (a com.mysql.jdbc.util.ReadAheadInputStream)
	at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2911)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3337)
	at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3327)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870)
	at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:1928)
	at com.mysql.jdbc.RowDataDynamic.nextRecord(RowDataDynamic.java:378)
	at com.mysql.jdbc.RowDataDynamic.next(RowDataDynamic.java:358)
	at com.mysql.jdbc.RowDataDynamic.close(RowDataDynamic.java:158)
	- locked <0x00000007d5d467e0> (a com.mysql.jdbc.JDBC4Connection)
	at com.mysql.jdbc.ResultSetImpl.realClose(ResultSetImpl.java:6702)
	- locked <0x00000007d5d467e0> (a com.mysql.jdbc.JDBC4Connection)
	at com.mysql.jdbc.ResultSetImpl.close(ResultSetImpl.java:842)

How to repeat:
run test code.
[26 Dec 2014 6:40] MySQL Verification Team
Hello Agapple wu,

Thank you for the report.

[10 Feb 2015 17:42] Daniel So
Added the following entry to the Connecotr/J 5.1.35 changelog:

"When in streaming mode, if Connector/J encountered an exception while reading from the stream, a subsequent call to the close() method of the result set would put the thread into a blocking state, from which it would not exit. With this fix, the result set can now be properly closed when, due to an error, there is no more data to be loaded from the stream."