Unverified Commit 3119a3ae authored by Binbin's avatar Binbin Committed by GitHub
Browse files

Fix CLIENT KILL kill all clients with id 0 (#9853)



* Fix CLIENT KILL kill all clients with id 0 or with skipme
CLIENT KILL with ID argument should only kill the client with the provided ID. In old code, 
CLIENT KILL with id 0 will kill all the connected clients.
Co-authored-by: default avatarOfir Luzon <ofirluzon@gmail.com>
parent 2386e541
...@@ -2741,10 +2741,11 @@ NULL ...@@ -2741,10 +2741,11 @@ NULL
int moreargs = c->argc > i+1; int moreargs = c->argc > i+1;
if (!strcasecmp(c->argv[i]->ptr,"id") && moreargs) { if (!strcasecmp(c->argv[i]->ptr,"id") && moreargs) {
long long tmp; long tmp;
if (getLongLongFromObjectOrReply(c,c->argv[i+1],&tmp,NULL) if (getRangeLongFromObjectOrReply(c, c->argv[i+1], 1, LONG_MAX, &tmp,
!= C_OK) return; "client-id should be greater than 0") != C_OK)
return;
id = tmp; id = tmp;
} else if (!strcasecmp(c->argv[i]->ptr,"type") && moreargs) { } else if (!strcasecmp(c->argv[i]->ptr,"type") && moreargs) {
type = getClientTypeByName(c->argv[i+1]->ptr); type = getClientTypeByName(c->argv[i+1]->ptr);
......
...@@ -13,6 +13,43 @@ start_server {tags {"introspection"}} { ...@@ -13,6 +13,43 @@ start_server {tags {"introspection"}} {
r client info r client info
} {*addr=*:* fd=* age=* idle=* flags=N db=* sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*} } {*addr=*:* fd=* age=* idle=* flags=N db=* sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
test {CLIENT KILL with illegal arguments} {
assert_error "ERR wrong number*" {r client kill}
assert_error "ERR syntax error*" {r client kill id 10 wrong_arg}
assert_error "ERR*greater than 0*" {r client kill id str}
assert_error "ERR*greater than 0*" {r client kill id -1}
assert_error "ERR*greater than 0*" {r client kill id 0}
assert_error "ERR Unknown client type*" {r client kill type wrong_type}
assert_error "ERR No such user*" {r client kill user wrong_user}
assert_error "ERR syntax error*" {r client kill skipme yes_or_no}
}
test {CLIENT KILL SKIPME YES/NO will kill all clients} {
# Kill all clients except `me`
set rd1 [redis_deferring_client]
set rd2 [redis_deferring_client]
set connected_clients [s connected_clients]
assert {$connected_clients >= 3}
set res [r client kill skipme yes]
assert {$res == $connected_clients - 1}
# Kill all clients, including `me`
set rd3 [redis_deferring_client]
set rd4 [redis_deferring_client]
set connected_clients [s connected_clients]
assert {$connected_clients == 3}
set res [r client kill skipme no]
assert_equal $res $connected_clients
# After killing `me`, the first ping will throw an error
assert_error "*I/O error*" {r ping}
assert_equal "PONG" [r ping]
}
test {MONITOR can log executed commands} { test {MONITOR can log executed commands} {
set rd [redis_deferring_client] set rd [redis_deferring_client]
$rd monitor $rd monitor
......
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