Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
7393fd81
Commit
7393fd81
authored
Sep 27, 2017
by
Dvir Volk
Browse files
Added safety net preventing redis from crashing if a module decide to block in MULTI
parent
b246635d
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
7393fd81
...
@@ -3401,14 +3401,16 @@ void unblockClientFromModule(client *c) {
...
@@ -3401,14 +3401,16 @@ void unblockClientFromModule(client *c) {
RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(void*), long long timeout_ms) {
RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc reply_callback, RedisModuleCmdFunc timeout_callback, void (*free_privdata)(void*), long long timeout_ms) {
client *c = ctx->client;
client *c = ctx->client;
int islua = c->flags & CLIENT_LUA;
int islua = c->flags & CLIENT_LUA;
int ismulti = c->flags & CLIENT_MULTI;
c->bpop.module_blocked_handle = zmalloc(sizeof(RedisModuleBlockedClient));
c->bpop.module_blocked_handle = zmalloc(sizeof(RedisModuleBlockedClient));
RedisModuleBlockedClient *bc = c->bpop.module_blocked_handle;
RedisModuleBlockedClient *bc = c->bpop.module_blocked_handle;
/* We need to handle the invalid operation of calling modules blocking
/* We need to handle the invalid operation of calling modules blocking
* commands from Lua. We actually create an already aborted (client set to
* commands from Lua or MULTI. We actually create an already aborted
* NULL) blocked client handle, and actually reply to Lua with an error. */
* (client set to NULL) blocked client handle, and actually reply with
bc
->
client
=
islua
?
NULL
:
c
;
* an error. */
bc->client = (islua || ismulti) ? NULL : c;
bc->module = ctx->module;
bc->module = ctx->module;
bc->reply_callback = reply_callback;
bc->reply_callback = reply_callback;
bc->timeout_callback = timeout_callback;
bc->timeout_callback = timeout_callback;
...
@@ -3419,9 +3421,10 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc
...
@@ -3419,9 +3421,10 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc
bc->dbid = c->db->id;
bc->dbid = c->db->id;
c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0;
c->bpop.timeout = timeout_ms ? (mstime()+timeout_ms) : 0;
if
(
islua
)
{
if (islua
|| ismulti
) {
c->bpop.module_blocked_handle = NULL;
c->bpop.module_blocked_handle = NULL;
addReplyError
(
c
,
"Blocking module command called from Lua script"
);
addReplyError(c, islua ? "Blocking module command called from Lua script" :
"Blocking module command called from transaction");
} else {
} else {
blockClient(c,BLOCKED_MODULE);
blockClient(c,BLOCKED_MODULE);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment