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

Allow Module blocking operations (not blocked on keys) to succeed when cluster is down #693

Merged
merged 8 commits into from
Jul 1, 2024
6 changes: 4 additions & 2 deletions src/cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,10 @@ void clusterRedirectClient(client *c, clusterNode *n, int hashslot, int error_co
* returns 1. Otherwise 0 is returned and no operation is performed. */
int clusterRedirectBlockedClientIfNeeded(client *c) {
clusterNode *myself = getMyClusterNode();
if (c->flags & CLIENT_BLOCKED && (c->bstate.btype == BLOCKED_LIST || c->bstate.btype == BLOCKED_ZSET ||
c->bstate.btype == BLOCKED_STREAM || c->bstate.btype == BLOCKED_MODULE)) {
if (c->flags & CLIENT_BLOCKED &&
(c->bstate.btype == BLOCKED_LIST || c->bstate.btype == BLOCKED_ZSET || c->bstate.btype == BLOCKED_STREAM ||
c->bstate.btype == BLOCKED_MODULE) &&
!clientHasModuleAuthInProgress(c)) {
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved
dictEntry *de;
dictIterator *di;

Expand Down
14 changes: 13 additions & 1 deletion tests/unit/moduleapi/cluster.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ tags {tls:skip external:skip cluster modules} {
set testmodule_nokey [file normalize tests/modules/blockonbackground.so]
set testmodule_blockedclient [file normalize tests/modules/blockedclient.so]
set testmodule [file normalize tests/modules/blockonkeys.so]
set testmodule_auth [file normalize tests/modules/auth.so]

set modules [list loadmodule $testmodule loadmodule $testmodule_nokey loadmodule $testmodule_blockedclient]
set modules [list loadmodule $testmodule loadmodule $testmodule_nokey loadmodule $testmodule_blockedclient loadmodule $testmodule_auth]
start_cluster 3 0 [list config_lines $modules] {

set node1 [srv 0 client]
Expand Down Expand Up @@ -158,6 +159,17 @@ start_cluster 3 0 [list config_lines $modules] {
assert_error "ERR Can not execute a command 'set' while the cluster is down" {$node1 do_rm_call set x 1}
}

test "Verify Module Auth Succeeds when cluster is down" {
r acl setuser foo >pwd on ~* &* +@all
assert_error "*cluster is down*" {$node1 set x 1}
KarthikSubbarao marked this conversation as resolved.
Show resolved Hide resolved
# Non Blocking Module Auth
assert_equal {OK} [r testmoduleone.rm_register_auth_cb]
KarthikSubbarao marked this conversation as resolved.
Show resolved Hide resolved
assert_equal {OK} [r AUTH foo allow]
# Blocking Module Auth
assert_equal {OK} [r testmoduleone.rm_register_blocking_auth_cb]
assert_equal {OK} [r AUTH foo block_allow]
}

resume_process $node3_pid
$node1_rd close
$node2_rd close
Expand Down
Loading