mirror of
https://github.com/redis/redis.git
synced 2026-04-21 03:01:35 -04:00
Fix crash on RM_Call with script mode. (#10886)
The PR fixes 2 issues: ### RM_Call crash on script mode `RM_Call` can potentially be called from a background thread where `server.current_client` are not set. In such case we get a crash on `NULL` dereference. The fix is to check first if `server.current_client` is `NULL`, if it does we should verify disc errors and readonly replica as we do to any normal clients (no masters nor AOF). ### RM_Call block OOM commands when not needed Again `RM_Call` can be executed on a background thread using a `ThreadSafeCtx`. In such case `server.pre_command_oom_state` can be irrelevant and should not be considered when check OOM state. This cause OOM commands to be blocked when not necessarily needed. In such case, check the actual used memory (and not the cached value). Notice that in order to know if the cached value can be used, we check that the ctx that was used on the `RM_Call` is a ThreadSafeCtx. Module writer can potentially abuse the API and use ThreadSafeCtx on the main thread. We consider this as a API miss used.
This commit is contained in:
committed by
GitHub
parent
a3fdc9cd82
commit
61baabd8d5
13
src/module.c
13
src/module.c
@@ -5783,7 +5783,16 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch
|
||||
|
||||
if (flags & REDISMODULE_ARGV_RESPECT_DENY_OOM) {
|
||||
if (cmd->flags & CMD_DENYOOM) {
|
||||
if (server.pre_command_oom_state) {
|
||||
int oom_state;
|
||||
if (ctx->flags & REDISMODULE_CTX_THREAD_SAFE) {
|
||||
/* On background thread we can not count on server.pre_command_oom_state.
|
||||
* Because it is only set on the main thread, in such case we will check
|
||||
* the actual memory usage. */
|
||||
oom_state = (getMaxmemoryState(NULL,NULL,NULL,NULL) == C_ERR);
|
||||
} else {
|
||||
oom_state = server.pre_command_oom_state;
|
||||
}
|
||||
if (oom_state) {
|
||||
errno = ENOSPC;
|
||||
if (error_as_call_replies) {
|
||||
sds msg = sdsdup(shared.oomerr->ptr);
|
||||
@@ -5823,7 +5832,7 @@ RedisModuleCallReply *RM_Call(RedisModuleCtx *ctx, const char *cmdname, const ch
|
||||
}
|
||||
|
||||
int deny_write_type = writeCommandsDeniedByDiskError();
|
||||
int obey_client = mustObeyClient(server.current_client);
|
||||
int obey_client = (server.current_client && mustObeyClient(server.current_client));
|
||||
|
||||
if (deny_write_type != DISK_ERROR_TYPE_NONE && !obey_client) {
|
||||
errno = ESPIPE;
|
||||
|
||||
Reference in New Issue
Block a user