From 0f75916a2e5d62c10daedc13dd3e1ebded4cad9d Mon Sep 17 00:00:00 2001 From: Christopher Troup Date: Mon, 6 Mar 2017 17:03:29 -0500 Subject: [PATCH] Ensure that users num_connections_used doesn't get incremented if connection rejected If the users connection is rejected we shouldn't be incrementing `num_connections_used` on the account_details object. This leads to `free_users` dropping below zero and _all_ subsequent requests getting rejected for that user. Refs #940 --- lib/MySQL_Authentication.cpp | 6 ++++-- lib/MySQL_Session.cpp | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/MySQL_Authentication.cpp b/lib/MySQL_Authentication.cpp index eba87de19..c283c7477 100644 --- a/lib/MySQL_Authentication.cpp +++ b/lib/MySQL_Authentication.cpp @@ -270,8 +270,10 @@ int MySQL_Authentication::increase_frontend_user_connections(char *username, int it = cg.bt_map.find(hash1); if (it != cg.bt_map.end()) { account_details_t *ad=it->second; - ad->num_connections_used++; - ret=ad->max_connections-ad->num_connections_used; + if (ad->max_connections > ad->num_connections_used) { + ret=ad->max_connections-ad->num_connections_used; + ad->num_connections_used++; + } if (mc) { *mc=ad->max_connections; } diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 77976d967..fb4bb0222 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -2572,7 +2572,7 @@ void MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE( client_authenticated=true; free_users=GloMyAuth->increase_frontend_user_connections(client_myds->myconn->userinfo->username, &used_users); } - if (max_connections_reached==true || free_users<0) { + if (max_connections_reached==true || free_users<=0) { *wrong_pass=true; client_myds->setDSS_STATE_QUERY_SENT_NET(); if (max_connections_reached==true) {