Uploaded image for project: 'MariaDB Connector/C'
  1. MariaDB Connector/C
  2. CONC-364

Not all sockets created in pvio_socket_connect function are closed

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 3.0.6
    • 3.0.7, 3.1.0
    • None
    • None
    • macOS 10.13.4

    Description

      The problem is reproducible if you try to connect to the inactive server on localhost(or 127.0.0.1).

      Open pvio_socket.c. The following call of getaddrinfo returns linked list of two items: IPv6 and IPv4 addresses

       /* Get the address information for the server using getaddrinfo() */
          wait_gai= 1;
          while ((gai_rc= getaddrinfo(cinfo->host, server_port,
                                      &hints, &res)) == EAI_AGAIN)
          {
      

      Then a new socket is created for each item in the list:

      for (save_res= res; save_res; save_res= save_res->ai_next)
          {
            csock->socket= socket(save_res->ai_family, save_res->ai_socktype, 
                                  save_res->ai_protocol);
      

      And attempt to connect:

      rc= pvio_socket_connect_sync_or_async(pvio, save_res->ai_addr, (uint)save_res->ai_addrlen);
      

      But when the error handling is made, only the last created socket is closed:

      /* close socket: MDEV-10891 */
        if (csock->socket != INVALID_SOCKET)
        {
          closesocket(csock->socket);
          csock->socket= INVALID_SOCKET;
        }
      

      While the previous (IPv6 in that case) remains not freed, which can be easily checked with lsof:

      $ lsof -p 95552 | grep CLOSED
      ClientApp 95552 sergey 18u IPv6 0x9bc9e6ea54fa1537 0t0 TCP localhost:64829->localhost:mysql (CLOSED)

      If multiple attempts are made the resource limit will be exceeded.

      Attachments

        Activity

          People

            georg Georg Richter
            sergey_pashkov Sergey Pashkov
            Votes:
            1 Vote for this issue
            Watchers:
            2 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.