Fix CLIENT UNBLOCK crashing modules. (#9167)
Modules that use background threads with thread safe contexts are likely
to use RM_BlockClient() without a timeout function, because they do not
set up a timeout.
Before this commit, `CLIENT UNBLOCK` would result with a crash as the
`NULL` timeout callback is called. Beyond just crashing, this is also
logically wrong as it may throw the module into an unexpected client
state.
This commits makes `CLIENT UNBLOCK` on such clients behave the same as
any other client that is not in a blocked state and therefore cannot be
unblocked.
(cherry picked from commit aa139e2f02)
This commit is contained in:
committed by
Oran Agra
parent
91bf2ab86d
commit
79fa5618f1
@@ -85,4 +85,33 @@ start_server {tags {"modules"}} {
|
||||
assert_equal [r slowlog len] 0
|
||||
}
|
||||
}
|
||||
|
||||
test "client unblock works only for modules with timeout support" {
|
||||
set rd [redis_deferring_client]
|
||||
$rd client id
|
||||
set id [$rd read]
|
||||
|
||||
# Block with a timeout function - may unblock
|
||||
$rd block.block 20000
|
||||
wait_for_condition 50 100 {
|
||||
[r block.is_blocked] == 1
|
||||
} else {
|
||||
fail "Module did not block"
|
||||
}
|
||||
|
||||
assert_equal 1 [r client unblock $id]
|
||||
assert_match {*Timed out*} [$rd read]
|
||||
|
||||
# Block without a timeout function - cannot unblock
|
||||
$rd block.block 0
|
||||
wait_for_condition 50 100 {
|
||||
[r block.is_blocked] == 1
|
||||
} else {
|
||||
fail "Module did not block"
|
||||
}
|
||||
|
||||
assert_equal 0 [r client unblock $id]
|
||||
assert_equal "OK" [r block.release foobar]
|
||||
assert_equal "foobar" [$rd read]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user