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
44aa22c6
Commit
44aa22c6
authored
Oct 28, 2019
by
Madelyn Olson
Browse files
Added better exception handling around scripting and module
parent
c95a582a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
44aa22c6
...
@@ -3174,6 +3174,8 @@ fmterr:
...
@@ -3174,6 +3174,8 @@ fmterr:
* EINVAL: wrong command arity.
* EINVAL: wrong command arity.
* ENOENT: command does not exist.
* ENOENT: command does not exist.
* EPERM: operation in Cluster instance with key in non local slot.
* EPERM: operation in Cluster instance with key in non local slot.
* EROFS: operation in Cluster instance when a write command is sent
* in a readonly state.
*
*
* This API is documented here: https://redis.io/topics/modules-intro
* This API is documented here: https://redis.io/topics/modules-intro
*/
*/
...
@@ -3231,13 +3233,18 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch
...
@@ -3231,13 +3233,18 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch
* trying to access non-local keys, with the exception of commands
* trying to access non-local keys, with the exception of commands
* received from our master. */
* received from our master. */
if
(
server
.
cluster_enabled
&&
!
(
ctx
->
client
->
flags
&
CLIENT_MASTER
))
{
if
(
server
.
cluster_enabled
&&
!
(
ctx
->
client
->
flags
&
CLIENT_MASTER
))
{
int
error_code
;
/* Duplicate relevant flags in the module client. */
/* Duplicate relevant flags in the module client. */
c
->
flags
&=
~
(
CLIENT_READONLY
|
CLIENT_ASKING
);
c
->
flags
&=
~
(
CLIENT_READONLY
|
CLIENT_ASKING
);
c
->
flags
|=
ctx
->
client
->
flags
&
(
CLIENT_READONLY
|
CLIENT_ASKING
);
c
->
flags
|=
ctx
->
client
->
flags
&
(
CLIENT_READONLY
|
CLIENT_ASKING
);
if
(
getNodeByQuery
(
c
,
c
->
cmd
,
c
->
argv
,
c
->
argc
,
NULL
,
NULL
)
!=
if
(
getNodeByQuery
(
c
,
c
->
cmd
,
c
->
argv
,
c
->
argc
,
NULL
,
&
error_code
)
!=
server
.
cluster
->
myself
)
server
.
cluster
->
myself
)
{
{
errno
=
EPERM
;
if
(
error_code
==
CLUSTER_REDIR_DOWN_STATE
)
{
errno
=
EROFS
;
}
else
{
errno
=
EPERM
;
}
goto
cleanup
;
goto
cleanup
;
}
}
}
}
...
...
src/scripting.c
View file @
44aa22c6
...
@@ -679,15 +679,23 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
...
@@ -679,15 +679,23 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
if
(
server
.
cluster_enabled
&&
!
server
.
loading
&&
if
(
server
.
cluster_enabled
&&
!
server
.
loading
&&
!
(
server
.
lua_caller
->
flags
&
CLIENT_MASTER
))
!
(
server
.
lua_caller
->
flags
&
CLIENT_MASTER
))
{
{
int
error_code
;
/* Duplicate relevant flags in the lua client. */
/* Duplicate relevant flags in the lua client. */
c
->
flags
&=
~
(
CLIENT_READONLY
|
CLIENT_ASKING
);
c
->
flags
&=
~
(
CLIENT_READONLY
|
CLIENT_ASKING
);
c
->
flags
|=
server
.
lua_caller
->
flags
&
(
CLIENT_READONLY
|
CLIENT_ASKING
);
c
->
flags
|=
server
.
lua_caller
->
flags
&
(
CLIENT_READONLY
|
CLIENT_ASKING
);
if
(
getNodeByQuery
(
c
,
c
->
cmd
,
c
->
argv
,
c
->
argc
,
NULL
,
NULL
)
!=
if
(
getNodeByQuery
(
c
,
c
->
cmd
,
c
->
argv
,
c
->
argc
,
NULL
,
&
error_code
)
!=
server
.
cluster
->
myself
)
server
.
cluster
->
myself
)
{
{
luaPushError
(
lua
,
if
(
error_code
==
CLUSTER_REDIR_DOWN_STATE
)
{
"Lua script attempted to access a non local key in a "
luaPushError
(
lua
,
"cluster node"
);
"Lua script attempted execute a write command while "
"cluster is down"
);
}
else
{
luaPushError
(
lua
,
"Lua script attempted to access a non local key in a "
"cluster node"
);
}
goto
cleanup
;
goto
cleanup
;
}
}
}
}
...
...
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