Skip to content

Commit d467cc0

Browse files
authored
Merge pull request #4083 from sysown/v2.x-fast_forward_ssl_230117
Consume all network buffer if SSL is in use
2 parents 420285e + 0231c9f commit d467cc0

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

lib/ClickHouse_Server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,11 +1375,11 @@ static void *child_mysql(void *arg) {
13751375
// PMC-10004
13761376
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
13771377
// if there is more data to be read, but it doesn't seem to be working.
1378-
// Therefore we hardcored the values 4096 (4K) as a special case and
1379-
// we try to call read_from_net() again.
1378+
// Therefore we try to call read_from_net() again as long as there is data.
13801379
// Previously we hardcoded 16KB but it seems that it can return in smaller
13811380
// chunks of 4KB.
1382-
while (rb > 0 && rb%4096 == 0) {
1381+
// We finally removed the chunk size as it seems that any size is possible.
1382+
while (rb > 0) {
13831383
rb = myds->read_from_net();
13841384
if (myds->net_failure) goto __exit_child_mysql;
13851385
myds->read_pkts();

lib/MySQL_Thread.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3598,15 +3598,17 @@ bool MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream *myds, unsigned
35983598
// PMC-10004
35993599
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
36003600
// if there is more data to be read, but it doesn't seem to be working.
3601-
// Therefore we hardcored the value 16384 (16KB) as a special case and
3602-
// we try to call read_from_net() again
3601+
// Therefore we try to call read_from_net() again as long as there is data.
3602+
// Previously we hardcoded 16KB but it seems that it can return in smaller
3603+
// chunks of 4KB.
3604+
// We finally removed the chunk size as it seems that any size is possible.
36033605
/*
36043606
int sslp = SSL_pending(myds->ssl);
36053607
int sslhp = SSL_has_pending(myds->ssl);
36063608
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);
36073609
*/
36083610
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);
3609-
while (rb == 16384) {
3611+
while (rb > 0) {
36103612
rb = myds->read_from_net();
36113613
if (rb > 0 && myds->myds_type == MYDS_FRONTEND) {
36123614
status_variables.stvar[st_var_queries_frontends_bytes_recv] += rb;

lib/ProxySQL_Admin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5466,11 +5466,11 @@ void *child_mysql(void *arg) {
54665466
// PMC-10004
54675467
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
54685468
// if there is more data to be read, but it doesn't seem to be working.
5469-
// Therefore we hardcored the values 4096 (4K) as a special case and
5470-
// we try to call read_from_net() again.
5469+
// Therefore we try to call read_from_net() again as long as there is data.
54715470
// Previously we hardcoded 16KB but it seems that it can return in smaller
54725471
// chunks of 4KB.
5473-
while (rb > 0 && rb%4096 == 0) {
5472+
// We finally removed the chunk size as it seems that any size is possible.
5473+
while (rb > 0) {
54745474
rb = myds->read_from_net();
54755475
if (myds->net_failure) goto __exit_child_mysql;
54765476
myds->read_pkts();

src/SQLite3_Server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,11 @@ static void *child_mysql(void *arg) {
944944
// PMC-10004
945945
// we probably should use SSL_pending() and/or SSL_has_pending() to determine
946946
// if there is more data to be read, but it doesn't seem to be working.
947-
// Therefore we hardcored the values 4096 (4K) as a special case and
948-
// we try to call read_from_net() again.
947+
// Therefore we try to call read_from_net() again as long as there is data.
949948
// Previously we hardcoded 16KB but it seems that it can return in smaller
950949
// chunks of 4KB.
951-
while (rb > 0 && rb%4096 == 0) {
950+
// We finally removed the chunk size as it seems that any size is possible.
951+
while (rb > 0) {
952952
rb = myds->read_from_net();
953953
if (myds->net_failure) goto __exit_child_mysql;
954954
myds->read_pkts();

test/tap/tests/test_ssl_fast_forward-1-t.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ std::vector<std::string> queries_SQL2 = {
6666
"INSERT INTO tbl1459 SELECT NULL , i1 + id, i2 + id FROM tbl1459",
6767
};
6868

69+
std::vector<std::string> queries_SQL4 = {
70+
"DROP TABLE IF EXISTS tbl1459",
71+
"VACUUM",
72+
};
73+
6974
std::vector<unsigned long long int> queries_limits = {
7075
1, 10, 20, 27, 103, 169, 320, 450, 512, 619, 915, 1022,
7176
1033, 1145, 1516, 1920, 2034, 5014, 9932, 10111,
@@ -255,6 +260,10 @@ int main(int argc, char** argv) {
255260

256261

257262

263+
// clean up
264+
if (run_queries_sets(queries_SQL4, mysqls[0], "Running on SQLite3"))
265+
return exit_status();
266+
258267

259268
for (int i=0; i<5; i++) {
260269
diag("Connection %d has thread_id: %lu", i, mysqls[i]->thread_id);

test/tap/tests/test_ssl_fast_forward-2-t.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ std::vector<std::string> queries_SQL3 = {
5555
"CREATE TABLE tbl1459v (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , t1 VARCHAR)",
5656
};
5757

58+
std::vector<std::string> queries_SQL4 = {
59+
"DROP TABLE IF EXISTS tbl1459v",
60+
"VACUUM",
61+
};
62+
5863

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

250258

251259
mysql_close(mysqladmin);

0 commit comments

Comments
 (0)