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
193e4acc
Commit
193e4acc
authored
Sep 27, 2017
by
Dvir Volk
Committed by
antirez
Oct 04, 2017
Browse files
Added safety net preventing redis from crashing if a module decide to block in MULTI
parent
d131921c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
193e4acc
...
...
@@ -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
)
{
client
*
c
=
ctx
->
client
;
int
islua
=
c
->
flags
&
CLIENT_LUA
;
int
ismulti
=
c
->
flags
&
CLIENT_MULTI
;
c
->
bpop
.
module_blocked_handle
=
zmalloc
(
sizeof
(
RedisModuleBlockedClient
));
RedisModuleBlockedClient
*
bc
=
c
->
bpop
.
module_blocked_handle
;
/* We need to handle the invalid operation of calling modules blocking
* commands from Lua. We actually create an already aborted (client set to
* NULL) blocked client handle, and actually reply to Lua with an error. */
bc
->
client
=
islua
?
NULL
:
c
;
* commands from Lua or MULTI. We actually create an already aborted
* (client set to NULL) blocked client handle, and actually reply with
* an error. */
bc
->
client
=
(
islua
||
ismulti
)
?
NULL
:
c
;
bc
->
module
=
ctx
->
module
;
bc
->
reply_callback
=
reply_callback
;
bc
->
timeout_callback
=
timeout_callback
;
...
...
@@ -3419,9 +3421,10 @@ RedisModuleBlockedClient *RM_BlockClient(RedisModuleCtx *ctx, RedisModuleCmdFunc
bc
->
dbid
=
c
->
db
->
id
;
c
->
bpop
.
timeout
=
timeout_ms
?
(
mstime
()
+
timeout_ms
)
:
0
;
if
(
islua
)
{
if
(
islua
||
ismulti
)
{
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
{
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