MXS-1263: Fix timeouts for partially established connections

When the connection timeout was checked for a connection, it assumed that
only valid and fully established sessions should be timed out.

Taking into account the fact that connections can be idle even before the
session is fully established, the check should be expanded to all
connections regardless of the session state.
This commit is contained in:
Markus Mäkelä
2017-05-11 09:31:59 +03:00
parent 09349aaa22
commit 6c583c43dd

View File

@ -214,6 +214,7 @@ dcb_alloc(dcb_role_t role, SERV_LISTENER *listener)
dcb_initialize(newdcb);
newdcb->dcb_role = role;
newdcb->listener = listener;
newdcb->last_read = hkheartbeat;
return newdcb;
}
@ -634,6 +635,7 @@ dcb_connect(SERVER *server, MXS_SESSION *session, const char *protocol)
pthread_self(), dcb);
dcb->persistentstart = 0;
dcb->was_persistent = true;
dcb->last_read = hkheartbeat;
return dcb;
}
else
@ -3385,19 +3387,27 @@ void dcb_process_idle_sessions(int thr)
{
if (dcb->dcb_role == DCB_ROLE_CLIENT_HANDLER)
{
MXS_SESSION *session = dcb->session;
ss_dassert(dcb->listener);
SERVICE *service = dcb->listener->service;
if (session->service && session->client_dcb &&
session->client_dcb->state == DCB_STATE_POLLING &&
session->service->conn_idle_timeout &&
hkheartbeat - session->client_dcb->last_read > session->service->conn_idle_timeout * 10)
if (service->conn_idle_timeout && dcb->state == DCB_STATE_POLLING)
{
int64_t idle = hkheartbeat - dcb->last_read;
int64_t timeout = service->conn_idle_timeout * 10;
if (idle > timeout)
{
MXS_WARNING("Timing out '%s'@%s, idle for %.1f seconds",
dcb->user ? dcb->user : "<unknown>",
dcb->remote ? dcb->remote : "<unknown>",
(float)idle / 10.f);
poll_fake_hangup_event(dcb);
}
}
}
}
}
}
bool dcb_foreach(bool(*func)(DCB *, void *), void *data)
{