Skip to content

Infinite loop in randomkey command on a replica with a database consisting solely of logically expired items #5015

@kevinmcgehee

Description

@kevinmcgehee

dbRandomKey() in db.c will not terminate when executed on a replica against a database where all items are logically expired. The function will only return under two conditions: there exist no keys in the dictionary, or a valid non-expired key is found. Given that replicas do not physically expire items and instead just skip returning them, an infinite loop occurs.

Reproduction steps:

$ redis-server --port 6379
$ redis-server --port 6380 --slaveof localhost 6379
$ redis-cli -p 6379
> set foo bar ex 10
$ kill -STOP <pid of first redis server>
$ redis-cli -p 6380
> get foo
"bar"
> get foo
(nil)
> randomkey

An infinite loop occurs on the follower, and even when the master is started again, the replica won't break out of the loop to consume the deletion.

On a related node, EXISTS returns true for logically expired keys on a replica, which is inconsistent with the rest of the read commands.

Both of these issues appear to be present in the latest unstable branch.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions