From f403402755d88a2669155a0f52c21f1bf616a67a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Jaramago=20Fern=C3=A1ndez?= Date: Mon, 10 May 2021 18:15:46 +0200 Subject: [PATCH] Added call to 'connect_cont' on timed out connections preventing 'fd' leak in connection destruction #3404 --- lib/MySQL_Session.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 859811541..6bbebe526 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2628,6 +2628,14 @@ bool MySQL_Session::handler_again___status_CONNECTING_SERVER(int *_rc) { previous_status.pop(); } if (mybe->server_myds->myconn) { + // Created connection never reached 'connect_cont' phase, due to that + // internal structures of 'mysql->net' are not fully initialized. + // This induces a leak of the 'fd' associated with the socket + // opened by the library. To prevent this, we need to call + // `mysql_real_connect_cont` through `connect_cont`. This way + // we ensure a proper cleanup of all the resources when 'mysql_close' + // is later called. For more context see issue #3404. + mybe->server_myds->myconn->connect_cont(MYSQL_WAIT_TIMEOUT); mybe->server_myds->destroy_MySQL_Connection_From_Pool(false); if (mirror) { PROXY_TRACE();