Uploaded image for project: 'MariaDB Connector/J'
  1. MariaDB Connector/J
  2. CONJ-1007

Socket file descriptors are leaked after connecting with unix socket if DB is not up running

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.7.7, 3.0.8
    • Component/s: Other
    • Labels:
      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              diego dupin Diego Dupin
              Reporter:
              guopengl Guopeng Liang
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.