Details
-
Bug
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
Description
If the connector is configured using unix socket, and attempts to connect when the DB is not up (the path to unix socket does not exist or not able to connect), it fails as expected. However after that, a socket file descriptor is not closed and leaked.
How to reproduce:
Add a unit test like this:
@Test
|
public void testConnectWithUnixSocketWhenDBNotUp () { |
|
String url = "jdbc:mariadb://localhost:3306"; |
Properties properties = new Properties(); |
properties.setProperty("localSocket", "/tmp/not_valid_socket"); |
properties.setProperty("localSocketAddress", "localhost"); |
|
java.sql.Driver driver = new org.mariadb.jdbc.Driver(); |
|
System.out.println ("Make a break point here and check netstat/lsof"); |
|
for (int i = 0; i < 10; i++) { |
assertThrows(SQLNonTransientConnectionException.class, () -> { |
driver.connect(url, properties);
|
});
|
}
|
|
System.out.println("Make a break point here and check again"); |
}
|
Run the unit test in a Linux env, and set break points as shown.
Use below commands to compare at the point of before and after making connections, and verify that the socket file descriptors are leaked.
Below example shows the "after" condition only:
#Find the process ID and replace here
> export pid=32532
> netstat -apnx | grep $pid
unix 2 [ ] STREAM CONNECTED 39256846 7767/java
unix 2 [ ] STREAM 39256869 7767/java
unix 2 [ ] STREAM 39256885 7767/java
unix 2 [ ] STREAM 39256871 7767/java
unix 2 [ ] STREAM 39256883 7767/java
unix 2 [ ] STREAM CONNECTED 39256860 7767/java
unix 2 [ ] STREAM 39256866 7767/java
unix 2 [ ] STREAM 39256873 7767/java
unix 2 [ ] STREAM 39256879 7767/java
unix 2 [ ] STREAM 39256877 7767/java
unix 2 [ ] STREAM 39256881 7767/java
unix 2 [ ] STREAM 39256875 7767/java
> lsof -p $pid | grep socket | wc -l
13