Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
2.5.2
-
Ubuntu 18.04.4 LTS, Java version: 11.0.7, Apache Maven 3.6.0, MariaDB Connector J 2.5.2+. And it seems I can only reproduce with cloud MySQL server
Description
After apply commit 4e0705bb306a5f7efef222c6886e3a561b13ab60, and run multi-thread program to connect to MySQL server with MariaDB Connector J , it has a high chance to meet with error "Access denied for xx".
Test code as follows:
|
import java.sql.*; |
import java.time.Instant; |
import java.util.Properties; |
|
public class TestCache extends Thread { |
// Default no of threads to 10 |
private static int NUM_OF_THREADS = 40; |
private static int LOOP = 5; |
private static int pass_conn = 0; |
static int c_nextId = 1; |
private static String url = "jdbc:mysql://server:3306/testj?user=user&password=password"; |
|
int m_myId; |
int pass_conn_i = 0; |
|
synchronized static int getNextId() { |
return c_nextId++; |
}
|
|
public static void main(String args[]) { |
try { |
// Load the JDBC driver |
Class.forName("org.mariadb.jdbc.Driver"); |
System.out.println("Driver loaded"); |
|
// Create the threads |
Thread[] threadList = new Thread[NUM_OF_THREADS]; |
|
double startTime = System.nanoTime(); |
// spawn threads |
for (int i = 0; i < NUM_OF_THREADS; i++) { |
threadList[i] = new TestCache(); |
threadList[i].start();
|
}
|
|
// wait for all threads to end |
for (int i = 0; i < NUM_OF_THREADS; i++) { |
threadList[i].join();
|
pass_conn += ((TestCache) threadList[i]).getPassCount();
|
}
|
|
double endTime = System.nanoTime(); |
double runtime = (endTime - startTime) / 1000000000; |
System.out.printf("Total runtime is %fs \n", runtime); |
System.out.printf("Throughput is : %f \n", pass_conn / runtime); |
System.out.printf("Pass rate is : %f \n", (double) pass_conn / (NUM_OF_THREADS * LOOP)); |
} catch (Exception e) { |
e.printStackTrace();
|
}
|
}
|
|
public TestCache() { |
super(); |
// Assign an Id to the thread |
m_myId = getNextId();
|
}
|
|
public void run() { |
int i = 0; |
int failureCount = 0; |
for (i = 0; i < LOOP; i++) { |
try { |
Connection conn = null; |
ResultSet rs = null; |
Statement stmt = null; |
|
Properties info = new Properties(); |
info.setProperty("pool", "0"); |
|
// Get the connection |
conn = DriverManager.getConnection(url, info);
|
stmt = conn.createStatement(); // Create a Statement |
|
// Execute the Query |
rs = stmt.executeQuery("select user() as user"); |
|
if (rs.next()) { |
pass_conn_i += 1; |
}
|
|
// Close all the resources |
rs.close();
|
rs = null; |
|
stmt.close();
|
stmt = null; |
|
conn.close();
|
conn = null; |
yield(); // Yield To other threads |
} catch (Exception e) { |
System.out.println("Thread " + m_myId + " got Exception: " + e); |
e.printStackTrace();
|
failureCount++;
|
yield(); // Yield To other threads |
}
|
}
|
System.out.println("Thread " + m_myId + " is finished. "); |
System.out.println("Failure Count: " + failureCount); |
yield(); // Yield To other threads |
}
|
|
public int getPassCount() { |
return pass_conn_i; |
}
|
|
}
|
|