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
Then a new socket is created for each item in the list:
And attempt to connect:
But when the error handling is made, only the last created socket is closed:
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.