summaryrefslogtreecommitdiff
path: root/src/networking.c
diff options
context:
space:
mode:
authorsundb <sundbcn@gmail.com>2021-06-18 02:49:15 +0800
committerGitHub <noreply@github.com>2021-06-17 21:49:15 +0300
commit1a22445d30809d36aa777f187c4217f38d11b53e (patch)
tree15f4ec799d170a7137846de03418b3e8bd515143 /src/networking.c
parenteae0983d2d5f13e0897494f2604a0df691c1678d (diff)
downloadredis-1a22445d30809d36aa777f187c4217f38d11b53e.tar.gz
Make readQueryFromClient more aggressive when reading big arg again (Followup for #9003) (#9100)
Due to the change in #9003, a long-standing bug was raised under `valgrind`. This bug can cause the master-slave sync to take a very long time, causing the `pendingquerybuf.tcl` test to fail. This problem does not only occur in master-slave sync, it is triggered when the big arg is greater than 32k. step: ```sh dd if=/dev/zero of=bigfile bs=1M count=32 ./src/redis-cli -x hset a a < bigfile ``` 1) Make room for querybuf in processMultibulkBuffer, now the alloc of querybuf will be more than 32k. 2) If this happens to trigger the `clientsCronResizeQueryBuffer`, querybuf will be resized to 0. 3) Finally, in readQueryFromClient, we expand the querybuf non-greedily, from 0 to 32k. Old code, make room for querybuf is greedy, so it only needs 11 times to expand to 32M(16k*(2^11)), but now we need 2048(32*1024/16) times to reach it, due to the slow allocation under valgrind that exposed the problem. The fix for the excessive shrinking of the query buf to 0, will be handled in #5013 (that other change on it's own can fix failing test too), but the fix in this PR will also fix the failing test. The fix in this PR will makes the reading in `readQueryFromClient` more aggressive when working on a big arg (so that it is in par with the same code in `processMultibulkBuffer` (i.e. the two calls to `sdsMakeRoomForNonGreedy` should both use the bulk size). In the code before this fix the one in readQueryFromClient always has `readlen = PROTO_IOBUF_LEN`
Diffstat (limited to 'src/networking.c')
-rw-r--r--src/networking.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/networking.c b/src/networking.c
index 652bdbf4b..b76ef7d08 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -2145,7 +2145,7 @@ void readQueryFromClient(connection *conn) {
/* Note that the 'remaining' variable may be zero in some edge case,
* for example once we resume a blocked client after CLIENT PAUSE. */
- if (remaining > 0 && (size_t)remaining < readlen) readlen = remaining;
+ if (remaining > 0) readlen = remaining;
}
qblen = sdslen(c->querybuf);