Commit 4779ed5e authored by Oran Agra's avatar Oran Agra
Browse files

Obuf limit, exit during loop in *RAND* commands

Related to the hang reported in #11671
Currently, redis can disconnect a client due to reaching output buffer limit,
it'll also avoid feeding that output buffer with more data, but it will keep
running the loop in the command (despite the client already being marked for
disconnection)

This PR is an attempt to mitigate the problem, specifically for commands that
are easy to abuse, specifically: SRANDMEMBER.
The RAND family of commands can take a negative COUNT argument (which is not
bound to the number of elements in the key), so it's enough to create a key
with one field, and then these commands can be used to hang redis.

NOTICE:
For in Redis 7.0 this fix handles KEYS as well, but in this branch
it doesn't, details in #11676
parent 2fc6a24f
...@@ -658,6 +658,8 @@ void srandmemberWithCountCommand(client *c) { ...@@ -658,6 +658,8 @@ void srandmemberWithCountCommand(client *c) {
} else { } else {
addReplyBulkCBuffer(c,ele,sdslen(ele)); addReplyBulkCBuffer(c,ele,sdslen(ele));
} }
if (c->flags & CLIENT_CLOSE_ASAP)
break;
} }
return; return;
} }
......
...@@ -168,4 +168,12 @@ start_server {tags {"obuf-limits"}} { ...@@ -168,4 +168,12 @@ start_server {tags {"obuf-limits"}} {
assert_equal "v2" [r get k2] assert_equal "v2" [r get k2]
assert_equal "v3" [r get k3] assert_equal "v3" [r get k3]
} }
test "Obuf limit, SRANDMEMBER with huge count stopped mid-run" {
r config set client-output-buffer-limit {normal 1000000 0 0}
r sadd myset a
catch {r srandmember myset -999999999} e
assert_match "*I/O error*" $e
reconnect
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment