From 7ad748d847e29aabe65ed509beefcafd37d16f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Fri, 14 Apr 2017 01:06:11 +0000 Subject: [PATCH] Fix infinite loop on broken connection #990 --- lib/MySQL_Thread.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 5b39ac6ee..c5670ae83 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -2624,6 +2624,21 @@ bool MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned } } if (myds->myds_type==MYDS_BACKEND && myds->sess->status!=FAST_FORWARD) { + if (mypolls.fds[n].revents) { + // this part of the code fixes an important bug + // if a connection in use but idle (ex: running a transaction) + // get data, immediately destroy the session + // + // this can happen, for example, with a low wait_timeout and running transaction + if (myds->sess->status==WAITING_CLIENT_DATA) { + if (myds->myconn->async_state_machine==ASYNC_IDLE) { + proxy_warning("Detected broken idle connection on %s:%d\n", myds->myconn->parent->address, myds->myconn->parent->port); + myds->destroy_MySQL_Connection_From_Pool(false); + myds->sess->set_unhealthy(); + return false; + } + } + } return true; } if (mypolls.fds[n].revents) {