Added better exception handling around scripting and module
This commit is contained in:
parent
c95a582a74
commit
44aa22c635
11
src/module.c
11
src/module.c
@ -3174,6 +3174,8 @@ fmterr:
|
||||
* EINVAL: wrong command arity.
|
||||
* ENOENT: command does not exist.
|
||||
* 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
|
||||
*/
|
||||
@ -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
|
||||
* received from our master. */
|
||||
if (server.cluster_enabled && !(ctx->client->flags & CLIENT_MASTER)) {
|
||||
int error_code;
|
||||
/* Duplicate relevant flags in the module client. */
|
||||
c->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)
|
||||
{
|
||||
errno = EPERM;
|
||||
if (error_code == CLUSTER_REDIR_DOWN_STATE) {
|
||||
errno = EROFS;
|
||||
} else {
|
||||
errno = EPERM;
|
||||
}
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
@ -679,15 +679,23 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
|
||||
if (server.cluster_enabled && !server.loading &&
|
||||
!(server.lua_caller->flags & CLIENT_MASTER))
|
||||
{
|
||||
int error_code;
|
||||
/* Duplicate relevant flags in the lua client. */
|
||||
c->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)
|
||||
{
|
||||
luaPushError(lua,
|
||||
"Lua script attempted to access a non local key in a "
|
||||
"cluster node");
|
||||
if (error_code == CLUSTER_REDIR_DOWN_STATE) {
|
||||
luaPushError(lua,
|
||||
"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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user