From 6653c494427f3d77c16fdec2a17b42ded0d8da2e Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Mon, 1 May 2023 02:44:13 +0500 Subject: [PATCH] If an error occurs while communicating with the backend server and the connection is SSL-based, OpenSSL's thread-based error queue is cleared. --- lib/MySQL_Monitor.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/MySQL_Monitor.cpp b/lib/MySQL_Monitor.cpp index 0fb01f666..a0b67343c 100644 --- a/lib/MySQL_Monitor.cpp +++ b/lib/MySQL_Monitor.cpp @@ -50,6 +50,10 @@ static MySQL_Monitor *GloMyMon; } while (rc!=SQLITE_DONE);\ } while (0) +#define MYSQL_OPENSSL_ERROR_CLEAR(_mysql) if (_mysql->options.use_ssl == 1) {\ + ERR_clear_error();\ +} + using std::string; using std::set; using std::vector; @@ -6923,6 +6927,11 @@ __again: t2 = monotonic_time(); if (interr) { mysql_error_msg = strdup(mysql_error(mysql)); + + // In the case of SSL-based connection to the backend server, any connection-related errors will cause + // all subsequent calls to the backend servers to fail. This is because OpenSSL maintains a thread-based error + // queue that must be cleared after an error occurs to ensure the next call executes successfully. + MYSQL_OPENSSL_ERROR_CLEAR(mysql); NEXT_IMMEDIATE(ASYNC_PING_FAILED); } else { NEXT_IMMEDIATE(ASYNC_PING_SUCCESSFUL); @@ -7075,6 +7084,11 @@ __again: t2 = monotonic_time(); if (interr) { mysql_error_msg = strdup(mysql_error(mysql)); + + // In the case of SSL-based connection to the backend server, any connection-related errors will cause + // all subsequent calls to the backend servers to fail. This is because OpenSSL maintains a thread-based error + // queue that must be cleared after an error occurs to ensure the next call executes successfully. + MYSQL_OPENSSL_ERROR_CLEAR(mysql); NEXT_IMMEDIATE(ASYNC_QUERY_FAILED); } else { NEXT_IMMEDIATE(ASYNC_QUERY_SUCCESSFUL); @@ -7111,6 +7125,11 @@ __again: t2 = monotonic_time(); if (mysql_errno(mysql)) { mysql_error_msg = strdup(mysql_error(mysql)); + + // In the case of SSL-based connection to the backend server, any connection-related errors will cause + // all subsequent calls to the backend servers to fail. This is because OpenSSL maintains a thread-based error + // queue that must be cleared after an error occurs to ensure the next call executes successfully. + MYSQL_OPENSSL_ERROR_CLEAR(mysql); NEXT_IMMEDIATE(ASYNC_STORE_RESULT_FAILED); } else { NEXT_IMMEDIATE(ASYNC_STORE_RESULT_SUCCESSFUL);