Skip to content

Commit d188715

Browse files
authored
Merge branch 'v3.0' into fix/issue-4855
Signed-off-by: René Cannaò <rene@proxysql.com>
2 parents 644174a + 3810922 commit d188715

File tree

11 files changed

+585
-158
lines changed

11 files changed

+585
-158
lines changed

include/GTID_Server_Data.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#ifndef CLASS_GTID_Server_Data_H
22
#define CLASS_GTID_Server_Data_H
3+
4+
#include <cstddef>
5+
#include <cstdint>
6+
#include <string>
7+
#include <proxysql_gtid.h>
8+
39
class GTID_Server_Data {
410
public:
511
char *address;
@@ -24,4 +30,7 @@ class GTID_Server_Data {
2430
void read_all_gtids();
2531
void dump();
2632
};
33+
34+
bool addGtidInterval(gtid_set_t& gtid_executed, std::string server_uuid, int64_t txid_start, int64_t txid_end);
35+
2736
#endif // CLASS_GTID_Server_Data_H

include/btree.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
#include <stddef.h>
105105
#include <string.h>
106106
#include <sys/types.h>
107+
#include <cstdint>
107108
#include <algorithm>
108109
#include <functional>
109110
#include <iostream>

include/proxysql_gtid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define PROXYSQL_GTID
33
// highly inspired by libslave
44
// https://github.com/vozbu/libslave/
5+
#include <string>
56
#include <unordered_map>
67
#include <list>
78
#include <utility>

lib/Admin_FlushVariables.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,36 @@ void ProxySQL_Admin::flush_mysql_variables___database_to_runtime(SQLite3DB *db,
549549
flush_GENERIC_variables__checksum__database_to_runtime("mysql", checksum, epoch);
550550
pthread_mutex_unlock(&GloVars.checksum_mutex);
551551
}
552+
553+
/**
554+
* @brief Check and warn if TCP keepalive is disabled for MySQL connections.
555+
*
556+
* This safety check warns users when mysql-use_tcp_keepalive is set to false,
557+
* which can cause connection instability in certain deployment scenarios.
558+
*
559+
* @warning Disabling TCP keepalive is unsafe when ProxySQL is deployed behind:
560+
* - Network load balancers with idle connection timeouts
561+
* - NAT firewalls with connection state timeout
562+
* - Cloud environments with connection pooling
563+
* - Any intermediate network device that drops idle connections
564+
*
565+
* @why_unsafe TCP keepalive sends periodic keep-alive packets on idle connections.
566+
* When disabled:
567+
* - Load balancers may drop connections from their connection pools
568+
* - NAT devices may remove connection state from their tables
569+
* - Cloud load balancers (AWS ELB, GCP Load Balancer, etc.) may terminate
570+
* connections during idle periods
571+
* - Results in sudden connection failures and "connection reset" errors
572+
* - Can cause application downtime and poor user experience
573+
*
574+
* @recommendation Always set mysql-use_tcp_keepalive=true when deploying
575+
* behind load balancers or in cloud environments.
576+
*/
577+
// Check for TCP keepalive setting and warn if disabled
578+
int mysql_use_tcp_keepalive = GloMTH->get_variable_int((char *)"use_tcp_keepalive");
579+
if (mysql_use_tcp_keepalive == 0) {
580+
proxy_warning("mysql-use_tcp_keepalive is set to false. This may cause connection drops when ProxySQL is behind a network load balancer. Consider setting this to true.\n");
581+
}
552582
}
553583
if (resultset) delete resultset;
554584
}
@@ -885,6 +915,40 @@ void ProxySQL_Admin::flush_pgsql_variables___database_to_runtime(SQLite3DB* db,
885915
GloVars.checksums_values.mysql_variables.checksum, GloVars.checksums_values.mysql_variables.epoch
886916
);
887917
*/
918+
919+
/**
920+
* @brief Check and warn if TCP keepalive is disabled for PostgreSQL connections.
921+
*
922+
* This safety check warns users when pgsql-use_tcp_keepalive is set to false,
923+
* which can cause connection instability in certain deployment scenarios.
924+
*
925+
* @warning Disabling TCP keepalive is unsafe when ProxySQL is deployed behind:
926+
* - Network load balancers with idle connection timeouts
927+
* - NAT firewalls with connection state timeout
928+
* - Cloud environments with connection pooling
929+
* - Any intermediate network device that drops idle connections
930+
*
931+
* @why_unsafe TCP keepalive sends periodic keep-alive packets on idle connections.
932+
* When disabled for PostgreSQL:
933+
* - Load balancers may drop connections from their connection pools
934+
* - NAT devices may remove connection state from their tables
935+
* - Cloud load balancers (AWS ELB, GCP Load Balancer, etc.) may terminate
936+
* connections during idle periods
937+
* - PostgreSQL connections may appear "stale" to the database server
938+
* - Results in sudden connection failures and "connection reset" errors
939+
* - Can cause application downtime and poor user experience
940+
*
941+
* @note PostgreSQL connections are often long-lived and benefit greatly from
942+
* TCP keepalive, especially in connection-pooled environments.
943+
*
944+
* @recommendation Always set pgsql-use_tcp_keepalive=true when deploying
945+
* behind load balancers or in cloud environments.
946+
*/
947+
// Check for TCP keepalive setting and warn if disabled
948+
int pgsql_use_tcp_keepalive = GloPTH->get_variable_int((char *)"use_tcp_keepalive");
949+
if (pgsql_use_tcp_keepalive == 0) {
950+
proxy_warning("pgsql-use_tcp_keepalive is set to false. This may cause connection drops when ProxySQL is behind a network load balancer. Consider setting this to true.\n");
951+
}
888952
}
889953
if (resultset) delete resultset;
890954
}

0 commit comments

Comments
 (0)