Unverified Commit eef29b68 authored by Gabi Ganam's avatar Gabi Ganam Committed by GitHub
Browse files

Blocking command with a 0.001 seconds timeout blocks indefinitely (#11688)

Any value in the range of [0-1) turns to 0 when being cast from double to long long. This change rounds up instead of down for values that can't be stored precisely as long doubles.
parent d0cc3de7
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include "server.h" #include "server.h"
#include "cluster.h" #include "cluster.h"
#include <math.h>
/* ========================== Clients timeouts ============================= */ /* ========================== Clients timeouts ============================= */
/* Check if this blocked client timedout (does nothing if the client is /* Check if this blocked client timedout (does nothing if the client is
...@@ -175,7 +177,7 @@ int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int ...@@ -175,7 +177,7 @@ int getTimeoutFromObjectOrReply(client *c, robj *object, mstime_t *timeout, int
addReplyError(c, "timeout is out of range"); addReplyError(c, "timeout is out of range");
return C_ERR; return C_ERR;
} }
tval = (long long) ftval; tval = (long long) ceill(ftval);
} else { } else {
if (getLongLongFromObjectOrReply(c,object,&tval, if (getLongLongFromObjectOrReply(c,object,&tval,
"timeout is not an integer or out of range") != C_OK) "timeout is not an integer or out of range") != C_OK)
......
...@@ -1263,6 +1263,16 @@ foreach {pop} {BLPOP BLMPOP_LEFT} { ...@@ -1263,6 +1263,16 @@ foreach {pop} {BLPOP BLMPOP_LEFT} {
$rd close $rd close
} }
test "$pop: with 0.001 timeout should not block indefinitely" {
# Use a timeout of 0.001 and wait for the number of blocked clients to equal 0.
# Validate the empty read from the deferring client.
set rd [redis_deferring_client]
bpop_command $rd $pop blist1 0.001
wait_for_blocked_clients_count 0
assert_equal {} [$rd read]
$rd close
}
test "$pop: second argument is not a list" { test "$pop: second argument is not a list" {
set rd [redis_deferring_client] set rd [redis_deferring_client]
r del blist1{t} blist2{t} r del blist1{t} blist2{t}
......
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