Skip to content

Commit c1e9186

Browse files
Sascha Rolandantirez
authored andcommitted
redis#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.
1 parent d60c17c commit c1e9186

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/t_stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,15 +1436,15 @@ void xreadCommand(client *c) {
14361436
* synchronously in case the group top item delivered is smaller
14371437
* than what the stream has inside. */
14381438
streamID *last = &groups[i]->last_id;
1439-
if (streamCompareID(&s->last_id, last) > 0) {
1439+
if (s->length && (streamCompareID(&s->last_id, last) > 0)) {
14401440
serve_synchronously = 1;
14411441
*gt = *last;
14421442
}
14431443
}
14441444
} else {
14451445
/* For consumers without a group, we serve synchronously if we can
14461446
* actually provide at least one item from the stream. */
1447-
if (streamCompareID(&s->last_id, gt) > 0) {
1447+
if (s->length && (streamCompareID(&s->last_id, gt) > 0)) {
14481448
serve_synchronously = 1;
14491449
}
14501450
}

0 commit comments

Comments
 (0)