Skip to content

Redis flushdb is causing error: "Redis server 127.0.0.1:6379 went away" #2312

@jessewaitz

Description

@jessewaitz

Expected behaviour

Flushing the db using the phpredis function flushdb() should clear the redis database, and if a new redis call comes in to check if a key exists or to set a new key, it should respond null, false, or fail gracefully.

Actual behaviour

Instead the redis server is causing subsequent redis calls, to check if a key exists, or set a new key, to throw a redisException: "Redis server 127.0.0.1:6379 went away"

Note: It appears that the errors only happen during the few milliseconds that the database is being cleared and the server is resetting. Our site gets close to 80k uniques a day so this problem is probably not seen on sites will way less visitors. But on our site we get at least 1 or 2 exceptions every time we clear the cache during business hours, at night when traffic is way less, this error never happens. But, after those couple exceptions, everything goes back to normal, and no additional exceptions happen until the redis db is flushed again.

In addition, this error is new since we upgraded the server to php 8.1 and our wordpress code to 6.1. Before this upgrade the redis keys hovered around 500k keys, but after the update to wp 6.1 our keys have quadrupled to about 2 million. So while I understand that wordpress is now using redis more heavily in its core functions, and a DB with 2 million keys is going to take longer to flush, shouldn't there be a way to make redis fail gracefully during this flushing process, instead of causing RedisExceptions.

I did add a php try/catch exception handler to the redis function that was causing the exception (in this first case, checking if a key exists). This worked for handling the exception for function. but then once that was handled the exceptions started firing on the setex() function. So it is just moving onto the next function after the exists() function returns null and is then trying to now set the key, and it is throwing the same exception on that function now.

Any help that you can give to reduce or eliminate these exceptions, would be greatly appreciated. thanks.

I'm seeing this behaviour on

  • OS: Ubuntu 20 (Linux 5.4.0-128-generic x86_64)
  • Redis: v7.0.5
  • PHP: v8.1.12
  • PhpRedis: v5.3.7

Steps to reproduce, backtrace or example script

See above, it happens every time I flush the db...

I've checked

  • [ X ] There is no similar issue from other users
  • [ X ] Issue isn't fixed in develop 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