summaryrefslogtreecommitdiff
path: root/src/networking.c
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 /src/networking.c
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 'src/networking.c')
-rw-r--r--src/networking.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/networking.c b/src/networking.c
index f633b41a4..224b7df4b 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -2342,6 +2342,9 @@ int processMultibulkBuffer(client *c) {
/* Hint the sds library about the amount of bytes this string is
* going to contain. */
c->querybuf = sdsMakeRoomForNonGreedy(c->querybuf,ll+2-sdslen(c->querybuf));
+ /* We later set the peak to the used portion of the buffer, but here we over
+ * allocated because we know what we need, make sure it'll not be shrunk before used. */
+ if (c->querybuf_peak < (size_t)ll + 2) c->querybuf_peak = ll + 2;
}
}
c->bulklen = ll;
@@ -2636,6 +2639,9 @@ void readQueryFromClient(connection *conn) {
* the query buffer, we also don't wanna use the greedy growth, in order
* to avoid collision with the RESIZE_THRESHOLD mechanism. */
c->querybuf = sdsMakeRoomForNonGreedy(c->querybuf, readlen);
+ /* We later set the peak to the used portion of the buffer, but here we over
+ * allocated because we know what we need, make sure it'll not be shrunk before used. */
+ if (c->querybuf_peak < qblen + readlen) c->querybuf_peak = qblen + readlen;
} else {
c->querybuf = sdsMakeRoomFor(c->querybuf, readlen);