@@ -1908,10 +1908,12 @@ bool MySQL_Session::handler_again___verify_backend_session_track_gtids() {
19081908 proxy_debug (PROXY_DEBUG_MYSQL_CONNECTION, 5 , " Session %p , client: %s , backend: %s\n " , this , client_myds->myconn ->options .session_track_gtids , mybe->server_myds ->myconn ->options .session_track_gtids );
19091909 // we first verify that the backend supports it
19101910 // if backend is old (or if it is not mysql) ignore this setting
1911- if ((mybe->server_myds ->myconn ->mysql ->server_capabilities & CLIENT_SESSION_TRACKING) == 0 ) {
1912- // the backend doesn't support CLIENT_SESSION_TRACKING
1913- return ret; // exit immediately
1911+ if ((mybe->server_myds ->myconn ->mysql ->server_capabilities & CLIENT_SESSION_TRACKING) == 0
1912+ || (mybe->server_myds ->myconn ->mysql ->server_capabilities & CLIENT_DEPRECATE_EOF) == 0
1913+ || mysql_thread___enable_server_deprecate_eof == false ) {
1914+ return ret;
19141915 }
1916+
19151917 uint32_t b_int = mybe->server_myds ->myconn ->options .session_track_gtids_int ;
19161918 uint32_t f_int = client_myds->myconn ->options .session_track_gtids_int ;
19171919
@@ -1958,16 +1960,26 @@ bool MySQL_Session::handler_again___verify_backend_session_track_gtids() {
19581960}
19591961
19601962bool MySQL_Session::handler_again___verify_backend_session_track_variables () {
1961- if (mysql_thread___session_track_variables == session_track_variables::DISABLED) {
1963+ int mode = mysql_thread___session_track_variables;
1964+
1965+ // skip enabling session variable tracking in the following cases
1966+ if (mode == session_track_variables::DISABLED) {
1967+ return false ;
1968+ }
1969+ if ((mybe->server_myds ->myconn ->mysql ->server_capabilities & CLIENT_SESSION_TRACKING) == 0
1970+ || (mybe->server_myds ->myconn ->mysql ->server_capabilities & CLIENT_DEPRECATE_EOF) == 0 ) {
1971+ return false ;
1972+ }
1973+ if (!mysql_thread___enable_server_deprecate_eof && mode != session_track_variables::ENFORCED) {
19621974 return false ;
19631975 }
19641976
1977+ // enable session tracking
19651978 if (mybe->server_myds ->myconn ->options .session_track_variables_sent == false ) {
19661979 mybe->server_myds ->myconn ->options .session_track_variables_sent = true ;
19671980 set_previous_status_mode3 ();
19681981 NEXT_IMMEDIATE_NEW (SETTING_SESSION_TRACK_VARIABLES);
19691982 }
1970-
19711983 if (mybe->server_myds ->myconn ->options .session_track_state_sent == false ) {
19721984 mybe->server_myds ->myconn ->options .session_track_state_sent = true ;
19731985 set_previous_status_mode3 ();
@@ -2937,6 +2949,11 @@ bool MySQL_Session::handler_again___status_CONNECTING_SERVER(int *_rc) {
29372949 }
29382950 enum session_status st=status;
29392951 if (mybe->server_myds ->myconn ->async_state_machine ==ASYNC_IDLE) {
2952+ if (handle_session_track_capabilities () == false ) {
2953+ pause_until = thread->curtime + mysql_thread___connect_retries_delay*1000 ;
2954+ return false ;
2955+ }
2956+
29402957 st=previous_status.top ();
29412958 previous_status.pop ();
29422959 NEXT_IMMEDIATE_NEW (st);
@@ -2966,6 +2983,12 @@ bool MySQL_Session::handler_again___status_CONNECTING_SERVER(int *_rc) {
29662983 previous_status.pop ();
29672984 myds->wait_until =0 ;
29682985
2986+ if (handle_session_track_capabilities () == false ) {
2987+ pause_until = thread->curtime + mysql_thread___connect_retries_delay*1000 ;
2988+ set_status (CONNECTING_SERVER);
2989+ return false ;
2990+ }
2991+
29692992 // NOTE: Even if a connection has correctly been created, since the CLIENT_DEPRECATE_EOF
29702993 // capability isn't always enforced to match for backend conns (no direct propagation), a
29712994 // mismatch can take place after the creation. Right now this is only true for
@@ -8271,3 +8294,41 @@ char* MySQL_Session::get_current_query(int max_length) {
82718294
82728295 return res;
82738296}
8297+
8298+ /* *
8299+ * @brief Handle session track capabilities validation.
8300+ *
8301+ * This function validates whether the backend connection has capabilities such as 'CLIENT_DEPRECATE_EOF'
8302+ * and 'CLIENT_SESSION_TRACKING' which are required to enable 'session_track_system_variables' in a MySQL session.
8303+ *
8304+ * If the connection lacks the capabilities and ProxySQL configuration is set in 'ENFORCED' mode, it returns the
8305+ * connection to the pool and set a backoff time for the backend server. This backoff time prevents the server from
8306+ * being selected again during connection pooling.
8307+ *
8308+ * @return 'true' if backend connection has required capabilities, otherwise returns 'false'.
8309+ */
8310+ bool MySQL_Session::handle_session_track_capabilities () {
8311+ if (mysql_thread___session_track_variables != session_track_variables::ENFORCED) {
8312+ return true ;
8313+ }
8314+
8315+ // this function should not be called in these states
8316+ if (mybe == NULL
8317+ || mybe->server_myds == NULL
8318+ || mybe->server_myds ->myconn == NULL
8319+ || mybe->server_myds ->myconn ->mysql == NULL ) {
8320+ return true ;
8321+ }
8322+
8323+ MySQL_Connection *be_conn = mybe->server_myds ->myconn ;
8324+ unsigned long srv_cap = be_conn->mysql ->server_capabilities ;
8325+
8326+ if ((srv_cap & CLIENT_DEPRECATE_EOF) == 0 || (srv_cap & CLIENT_SESSION_TRACKING) == 0 ) {
8327+ // be_conn->parent->server_backoff_time = thread->curtime + (600 * 1000000); // 10 minutes
8328+ be_conn->parent ->server_backoff_time = thread->curtime + (30 * 1000000 ); // 30 seconds
8329+ mybe->server_myds ->return_MySQL_Connection_To_Pool ();
8330+ return false ;
8331+ }
8332+
8333+ return true ;
8334+ }
0 commit comments