mirror of
http://github.com/valkey-io/valkey
synced 2024-11-22 18:04:52 +00:00
Fix module blocked clients RESP version (#9634)
Before this commit, module blocked clients did not carry through the original RESP version, resulting with RESP3 clients receiving unexpected RESP2 replies.
This commit is contained in:
parent
8f745da159
commit
cf860df599
@ -6181,6 +6181,8 @@ RedisModuleBlockedClient *moduleBlockClient(RedisModuleCtx *ctx, RedisModuleCmdF
|
||||
bc->free_privdata = free_privdata;
|
||||
bc->privdata = privdata;
|
||||
bc->reply_client = createClient(NULL);
|
||||
if (bc->client)
|
||||
bc->reply_client->resp = bc->client->resp;
|
||||
bc->reply_client->flags |= CLIENT_MODULE;
|
||||
bc->dbid = c->db->id;
|
||||
bc->blocked_on_keys = keys != NULL;
|
||||
@ -6654,7 +6656,10 @@ RedisModuleCtx *RM_GetThreadSafeContext(RedisModuleBlockedClient *bc) {
|
||||
ctx->client = createClient(NULL);
|
||||
if (bc) {
|
||||
selectDb(ctx->client,bc->dbid);
|
||||
if (bc->client) ctx->client->id = bc->client->id;
|
||||
if (bc->client) {
|
||||
ctx->client->id = bc->client->id;
|
||||
ctx->client->resp = bc->client->resp;
|
||||
}
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
@ -188,6 +188,21 @@ int do_rm_call(RedisModuleCtx *ctx, RedisModuleString **argv, int argc){
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
/* simulate a blocked client replying to a thread safe context without creating a thread */
|
||||
int do_fake_bg_true(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
UNUSED(argv);
|
||||
UNUSED(argc);
|
||||
|
||||
RedisModuleBlockedClient *bc = RedisModule_BlockClient(ctx, NULL, NULL, NULL, 0);
|
||||
RedisModuleCtx *bctx = RedisModule_GetThreadSafeContext(bc);
|
||||
|
||||
RedisModule_ReplyWithBool(bctx, 1);
|
||||
|
||||
RedisModule_FreeThreadSafeContext(bctx);
|
||||
RedisModule_UnblockClient(bc, NULL);
|
||||
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
||||
int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) {
|
||||
REDISMODULE_NOT_USED(argv);
|
||||
@ -205,5 +220,8 @@ int RedisModule_OnLoad(RedisModuleCtx *ctx, RedisModuleString **argv, int argc)
|
||||
if (RedisModule_CreateCommand(ctx, "do_bg_rm_call", do_bg_rm_call, "", 0, 0, 0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
|
||||
if (RedisModule_CreateCommand(ctx, "do_fake_bg_true", do_fake_bg_true, "", 0, 0, 0) == REDISMODULE_ERR)
|
||||
return REDISMODULE_ERR;
|
||||
|
||||
return REDISMODULE_OK;
|
||||
}
|
||||
|
@ -78,6 +78,20 @@ start_server {tags {"modules"}} {
|
||||
r do_bg_rm_call hgetall hash
|
||||
} {foo bar}
|
||||
|
||||
test {RESP version carries through to blocked client} {
|
||||
for {set client_proto 2} {$client_proto <= 3} {incr client_proto} {
|
||||
r hello $client_proto
|
||||
r readraw 1
|
||||
set ret [r do_fake_bg_true]
|
||||
if {$client_proto == 2} {
|
||||
assert_equal $ret {:1}
|
||||
} else {
|
||||
assert_equal $ret "#t"
|
||||
}
|
||||
r readraw 0
|
||||
}
|
||||
}
|
||||
|
||||
test {blocked client reaches client output buffer limit} {
|
||||
r hset hash big [string repeat x 50000]
|
||||
r hset hash bada [string repeat x 50000]
|
||||
|
Loading…
Reference in New Issue
Block a user