Skip to content

Commit

Permalink
Merge pull request #4083 from sysown/v2.x-fast_forward_ssl_230117
Browse files Browse the repository at this point in the history
Consume all network buffer if SSL is in use
  • Loading branch information
renecannao authored Jan 18, 2023
2 parents 420285e + 0231c9f commit d467cc0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
6 changes: 3 additions & 3 deletions lib/ClickHouse_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1375,11 +1375,11 @@ static void *child_mysql(void *arg) {
// PMC-10004
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
// if there is more data to be read, but it doesn't seem to be working.
// Therefore we hardcored the values 4096 (4K) as a special case and
// we try to call read_from_net() again.
// Therefore we try to call read_from_net() again as long as there is data.
// Previously we hardcoded 16KB but it seems that it can return in smaller
// chunks of 4KB.
while (rb > 0 && rb%4096 == 0) {
// We finally removed the chunk size as it seems that any size is possible.
while (rb > 0) {
rb = myds->read_from_net();
if (myds->net_failure) goto __exit_child_mysql;
myds->read_pkts();
Expand Down
8 changes: 5 additions & 3 deletions lib/MySQL_Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3598,15 +3598,17 @@ bool MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned
// PMC-10004
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
// if there is more data to be read, but it doesn't seem to be working.
// Therefore we hardcored the value 16384 (16KB) as a special case and
// we try to call read_from_net() again
// Therefore we try to call read_from_net() again as long as there is data.
// Previously we hardcoded 16KB but it seems that it can return in smaller
// chunks of 4KB.
// We finally removed the chunk size as it seems that any size is possible.
/*
int sslp = SSL_pending(myds->ssl);
int sslhp = SSL_has_pending(myds->ssl);
proxy_debug(PROXY_DEBUG_NET, 5, "Session=%p: in fast_forward mode and SSL read %d bytes , SSL_pending: %d bytes , SSL_has_pending: %d\n", myds->sess, rb, sslp, sslhp);
*/
proxy_debug(PROXY_DEBUG_NET, 5, "Session=%p, DataStream=%p , thread_session_id=%u -- in fast_forward mode and SSL read %d bytes\n", myds->sess, myds, myds->sess->thread_session_id, rb);
while (rb == 16384) {
while (rb > 0) {
rb = myds->read_from_net();
if (rb > 0 && myds->myds_type == MYDS_FRONTEND) {
status_variables.stvar[st_var_queries_frontends_bytes_recv] += rb;
Expand Down
6 changes: 3 additions & 3 deletions lib/ProxySQL_Admin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5466,11 +5466,11 @@ void *child_mysql(void *arg) {
// PMC-10004
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
// if there is more data to be read, but it doesn't seem to be working.
// Therefore we hardcored the values 4096 (4K) as a special case and
// we try to call read_from_net() again.
// Therefore we try to call read_from_net() again as long as there is data.
// Previously we hardcoded 16KB but it seems that it can return in smaller
// chunks of 4KB.
while (rb > 0 && rb%4096 == 0) {
// We finally removed the chunk size as it seems that any size is possible.
while (rb > 0) {
rb = myds->read_from_net();
if (myds->net_failure) goto __exit_child_mysql;
myds->read_pkts();
Expand Down
6 changes: 3 additions & 3 deletions src/SQLite3_Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,11 +944,11 @@ static void *child_mysql(void *arg) {
// PMC-10004
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
// if there is more data to be read, but it doesn't seem to be working.
// Therefore we hardcored the values 4096 (4K) as a special case and
// we try to call read_from_net() again.
// Therefore we try to call read_from_net() again as long as there is data.
// Previously we hardcoded 16KB but it seems that it can return in smaller
// chunks of 4KB.
while (rb > 0 && rb%4096 == 0) {
// We finally removed the chunk size as it seems that any size is possible.
while (rb > 0) {
rb = myds->read_from_net();
if (myds->net_failure) goto __exit_child_mysql;
myds->read_pkts();
Expand Down
9 changes: 9 additions & 0 deletions test/tap/tests/test_ssl_fast_forward-1-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ std::vector<std::string> queries_SQL2 = {
"INSERT INTO tbl1459 SELECT NULL , i1 + id, i2 + id FROM tbl1459",
};

std::vector<std::string> queries_SQL4 = {
"DROP TABLE IF EXISTS tbl1459",
"VACUUM",
};

std::vector<unsigned long long int> queries_limits = {
1, 10, 20, 27, 103, 169, 320, 450, 512, 619, 915, 1022,
1033, 1145, 1516, 1920, 2034, 5014, 9932, 10111,
Expand Down Expand Up @@ -255,6 +260,10 @@ int main(int argc, char** argv) {



// clean up
if (run_queries_sets(queries_SQL4, mysqls[0], "Running on SQLite3"))
return exit_status();


for (int i=0; i<5; i++) {
diag("Connection %d has thread_id: %lu", i, mysqls[i]->thread_id);
Expand Down
8 changes: 8 additions & 0 deletions test/tap/tests/test_ssl_fast_forward-2-t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ std::vector<std::string> queries_SQL3 = {
"CREATE TABLE tbl1459v (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , t1 VARCHAR)",
};

std::vector<std::string> queries_SQL4 = {
"DROP TABLE IF EXISTS tbl1459v",
"VACUUM",
};


int run_queries_sets(std::vector<std::string>& queries, MYSQL *my, const std::string& message_prefix) {
for (std::vector<std::string>::iterator it = queries.begin(); it != queries.end(); it++) {
Expand Down Expand Up @@ -246,6 +251,9 @@ int main(int argc, char** argv) {
}
}
}
// clean up
if (run_queries_sets(queries_SQL4, mysqls[0], "Running on SQLite3"))
return exit_status();


mysql_close(mysqladmin);
Expand Down

0 comments on commit d467cc0

Please sign in to comment.