Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect on READONLY error #79

Open
Yenya opened this issue Jun 29, 2023 · 0 comments
Open

Reconnect on READONLY error #79

Yenya opened this issue Jun 29, 2023 · 0 comments

Comments

@Yenya
Copy link
Contributor

Yenya commented Jun 29, 2023

When the Redis server does failover to a replica using master-slave replication, the old master is demoted to read-only (either manually or by a sentinel), read operations can continue, but writers receive a READONLY error message, and are expected to reconnect to a newly promoted replica. In Redis::Fast, this can be handled by setting up a hook on the READONLY error message. From their documentation:

my $r = Redis::Fast->new(
  reconnect          => 1, # The value greater than 0 is required
  reconnect_on_error => sub {
    my ($error, $ret, $command) = @_;
    if ($error =~ /READONLY You can't write against a read only slave/) {
      # force reconnect
      return 1;
    }
    # do nothing
    return -1;
  },
);

In Mojo::Redis this is not possible, because the Mojo::Redis::Connection->on(error => ...) event gets emitted only when the current request is not a promise, and it is called for a single connection out of many in the connection pool. Also, I am not sure whether the event handler can lead to resubmitting the current request.

Please support a sane way how to detect a server failover to another replica, and reconnect in case the server goes read-only. So far it seems that Mojo::Redis stays connected to the old master indefinitely, and keeps getting the READONLY errors for write requests.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant