Bug #117627 useCompression=true cause Direct Memory rise
Submitted: 6 Mar 1:52 Modified: 12 Jun 11:01
Reporter: Yong Xie Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / J Severity:S2 (Serious)
Version:8.0.25 OS:Linux
Assigned to: CPU Architecture:Any

[6 Mar 1:52] Yong Xie
Description:
We recently upgraded our JDBC version from 5.1.40 to 8.0.25, and subsequently observed that the off-heap(Direct Memory) memory usage in our container kept increasing until it eventually caused an out-of-memory error and triggered a container restart after about a week. After removing the useCompression=true parameter, we found that the container operated normally. This issue was not observed with the 5.1.40 version.

How to repeat:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 
 */
public class JDBCCompressTest {
	protected static String driver = "com.mysql.cj.jdbc.Driver";
	protected static String url = "jdbc:mysql://localhost:3306/demo?autoReconnect=true&characterEncoding=utf8&useCompression=true";
	protected static String user = "root";
	protected static String password = "xxxxxx";
	
	public static Connection getConnection() {
		try {
			Class.forName(driver);
			return DriverManager.getConnection(url, user, password);
		} catch (ClassNotFoundException e) {
			System.out.println("Can't find mysql driver!");
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public static void main(String[] args) {
		int testSize = 63000;
		String sql = "select * from events";
		System.out.println("testSize = " + testSize);
		
		for(int i=0; i< testSize; i++){
			try {
				Connection conn = getConnection();
				Statement sm = conn.createStatement();
				ResultSet rs = sm.executeQuery(sql);
				rs.next();
				sm.close();
				rs.close();
				conn.close();
				Thread.sleep(1000);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		System.out.println("Done");
		 
        //Let it run for a while so I can monitor the java process.
        try{ Thread.sleep(60*60*1000); }catch(InterruptedException ex){}
	}
}
[7 Mar 12:52] MySQL Verification Team
Hello Yong Xie,

Thank you for the report and test case.
Please note that MySQL Connector/J 8.0.25 (2021-05-11, General Availability) is very old version and since then many bugs fixed. I would request/suggest you to try current GA i.e. MySQL Connector/J 9.2.0 (2025-01-21, General Availability) and confirm if you are still seeing the issue along with table structure(output of SHOW CREATE TABLE events\G statement) and if possible logical dump of the table or just table size to investigate further. Thank you.

regards,
Umesh
[8 Apr 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[12 Jun 8:59] Yong Xie
Thank you for your response. Our test results show that this issue does not exist in version 9.2.0.
[12 Jun 11:01] MySQL Verification Team
Thank you for confirming.
Closing the report for now.

regards,
Umesh