summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorjudeng <abc3844@126.com>2023-04-16 20:49:26 +0800
committerGitHub <noreply@github.com>2023-04-16 15:49:26 +0300
commite7f18432b8e9e1d1998d3a898006497e6c5e5a32 (patch)
treee168db166288fed2477e543056587b859d5a32fa /tests
parent1222b6087385aa431a412a9e9b59cf29ce55210e (diff)
downloadredis-e7f18432b8e9e1d1998d3a898006497e6c5e5a32.tar.gz
avoid incorrect shrinking of querybuf when client is reading a big argv (#12000)
this pr fix two wrongs: 1. When client’s querybuf is pre-allocated for a fat argv, we need to update the querybuf_peak of the client immediately to completely avoid the unexpected shrinking of querybuf in the next clientCron (before data arrives to set the peak). 2. the protocol's bulklen does not include `\r\n`, but the allocation and the data we read does. so in `clientsCronResizeQueryBuffer`, the `resize` or `querybuf_peak` should add these 2 bytes. the first bug is likely to hit us on large payloads over slow connections, in which case transferring the payload can take longer and a cron event will be triggered (specifically if there are not a lot of clients)
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/querybuf.tcl24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/unit/querybuf.tcl b/tests/unit/querybuf.tcl
index bbbea12f4..c66f5c250 100644
--- a/tests/unit/querybuf.tcl
+++ b/tests/unit/querybuf.tcl
@@ -18,6 +18,8 @@ proc client_query_buffer {name} {
}
start_server {tags {"querybuf slow"}} {
+ # increase the execution frequency of clientsCron
+ r config set hz 100
# The test will run at least 2s to check if client query
# buffer will be resized when client idle 2s.
test "query buffer resized correctly" {
@@ -63,4 +65,26 @@ start_server {tags {"querybuf slow"}} {
assert {[client_query_buffer test_client] > 0 && [client_query_buffer test_client] < $orig_test_client_qbuf}
$rd close
}
+
+ test "query buffer resized correctly with fat argv" {
+ set rd [redis_client]
+ $rd client setname test_client
+ $rd write "*3\r\n\$3\r\nset\r\n\$1\r\na\r\n\$1000000\r\n"
+ $rd flush
+
+ after 20
+ if {[client_query_buffer test_client] < 1000000} {
+ fail "query buffer should not be resized when client idle time smaller than 2s"
+ }
+
+ # Check that the query buffer is resized after 2 sec
+ wait_for_condition 1000 10 {
+ [client_idle_sec test_client] >= 3 && [client_query_buffer test_client] < 1000000
+ } else {
+ fail "query buffer should be resized when client idle time bigger than 2s"
+ }
+
+ $rd close
+ }
+
}