summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Roland <sroland@ngncc.de>2018-08-29 17:53:47 +0200
committerantirez <antirez@gmail.com>2018-09-04 13:13:36 +0200
commitc1e9186f069e0b3aa1507e0e86a16d5001ea5420 (patch)
tree37545214b296f0a41f99a6ac0fd3350c039cefef
parentd60c17cbb3ae0a4b1a435f0b6fc986a60449ebec (diff)
downloadredis-c1e9186f069e0b3aa1507e0e86a16d5001ea5420.tar.gz
#5299 Fix blocking XREAD for streams that ran dry
The conclusion, that a xread request can be answered syncronously in case that the stream's last_id is larger than the passed last-received-id parameter, assumes, that there must be entries present, which could be returned immediately. This assumption fails for empty streams that actually contained some entries which got removed by xdel, ... . As result, the client is answered synchronously with an empty result, instead of blocking for new entries to arrive. An additional check for a non-empty stream is required.
-rw-r--r--src/t_stream.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/t_stream.c b/src/t_stream.c
index 77fbf4645..40e0c84b8 100644
--- a/src/t_stream.c
+++ b/src/t_stream.c
@@ -1436,7 +1436,7 @@ void xreadCommand(client *c) {
* synchronously in case the group top item delivered is smaller
* than what the stream has inside. */
streamID *last = &groups[i]->last_id;
- if (streamCompareID(&s->last_id, last) > 0) {
+ if (s->length && (streamCompareID(&s->last_id, last) > 0)) {
serve_synchronously = 1;
*gt = *last;
}
@@ -1444,7 +1444,7 @@ void xreadCommand(client *c) {
} else {
/* For consumers without a group, we serve synchronously if we can
* actually provide at least one item from the stream. */
- if (streamCompareID(&s->last_id, gt) > 0) {
+ if (s->length && (streamCompareID(&s->last_id, gt) > 0)) {
serve_synchronously = 1;
}
}