New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory leak while getting multiple connections with the same parameters [JDBC249] #298
Comments
Commented by: @mrotteveel Where is FBConnectionProperties being used as a key to a Map / HashTable? I quickly scanned to code, but couldn't find it. |
Commented by: @alexeykovyazin sorry for incomplete description FBConnectionProperties is not used as a key, key is instance of FBManagedConnectionFactory mcf private FBDataSource createDataSource(FBManagedConnectionFactory mcf) throws ResourceException {
} and FBManagedConnectionFactory in the implementation of equals/hashCode uses FBConnectionProperties.equals/hashCode |
Modified by: @mrotteveelassignee: Roman Rokytskyy [ rrokytskyy ] => Mark Rotteveel [ avalanche1979 ] |
Commented by: @mrotteveel It looks like removing mapper from hashCode and equals, and make sure the defaultIsolation is recorded in FBConnectionProperties if it is changed will fix this specific problem. Limiting the hashCode to database and type could be good enough and leave the rest to equals. I will need to research and test this a little bit longer. |
Commented by: @mrotteveel Committed fix; I reduced the hashCode calculation to the most stable fields so it should remain stable. Also fixed a potential thread safety issue. I also changed the storage of mcfToDataSourceMap to a WeakHashMap to prevent a potential different memory leak, but I am not 100% sure if that worked (limited testing did not reveal it getting garbage collected). |
Commented by: @mrotteveel Fixed for Jaybird-2.2 after beta-1 |
Modified by: @mrotteveelFix Version: Jaybird 2.2 [ 10053 ] |
Modified by: @mrotteveelstatus: Resolved [ 5 ] => Closed [ 6 ] |
Submitted by: @alexeykovyazin
Currently to generate key for hash table of FBConnectionProperties field "mapper" is used. This field is being lazy initialized during the first getMapper() call.
So after the first such call hash key became different from stored, equals() gives the false result and another copy of FBConnectionProperties is added.
Getting new connection with the same URL and properties makes hash table to grow infinitely.
There is few bytes leak per connection, but this became critical after 20-30 thousands of connects/disconnects.
public class DriverTest {
protected static final int CONNECTIONS_COUNT = 1000000;
@test
public void createManyConnectionsWithSameProperties() throws Exception {
new FBDriver();
final Runtime rt = Runtime.getRuntime();
for ( int i = 0; i < CONNECTIONS_COUNT; i++ ) {
final Connection connection = DriverManager.getConnection(
"jdbc:firebirdsql:localhost/3050:/Library/Frameworks/Firebird.framework/Versions/Current/Resources/examples/empbuild/employee.fdb",
"SYSDBA", "masterkey"
);
connection.close();
if ( i % 50 == 0 ) {
System.gc();
System.out.printf(""+i
+" free mem: %d b\n",
rt.freeMemory()
);
}
}
}
}
Commits: 9acadc0
The text was updated successfully, but these errors were encountered: