summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSalvatore Sanfilippo <antirez@gmail.com>2020-04-06 11:59:01 +0200
committerGitHub <noreply@github.com>2020-04-06 11:59:01 +0200
commitaf5c11874c4e534db0ca1c44c2ca20fec1ab2700 (patch)
treedcdc692418ef2ee3355b4f90ce2d6e539a2ab2ba
parent4bc4d2c7676430b752cb1f7114bfdc76a49b260d (diff)
parent38f6207f884f514e928513acb6560fdb375daa2e (diff)
downloadredis-af5c11874c4e534db0ca1c44c2ca20fec1ab2700.tar.gz
Merge pull request #6797 from patpatbear/issue_#6565_memory_borderline
Check OOM at script start to get stable lua OOM state.
-rw-r--r--src/scripting.c7
-rw-r--r--src/server.c7
-rw-r--r--src/server.h1
3 files changed, 11 insertions, 4 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 7f64e06db..32a511e13 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -657,12 +657,11 @@ int luaRedisGenericCommand(lua_State *lua, int raise_error) {
!server.loading && /* Don't care about mem if loading. */
!server.masterhost && /* Slave must execute the script. */
server.lua_write_dirty == 0 && /* Script had no side effects so far. */
+ server.lua_oom && /* Detected OOM when script start. */
(cmd->flags & CMD_DENYOOM))
{
- if (getMaxmemoryState(NULL,NULL,NULL,NULL) != C_OK) {
- luaPushError(lua, shared.oomerr->ptr);
- goto cleanup;
- }
+ luaPushError(lua, shared.oomerr->ptr);
+ goto cleanup;
}
if (cmd->flags & CMD_RANDOM) server.lua_random_dirty = 1;
diff --git a/src/server.c b/src/server.c
index 9ebf0ee6b..d6abc72d9 100644
--- a/src/server.c
+++ b/src/server.c
@@ -3441,6 +3441,13 @@ int processCommand(client *c) {
addReply(c, shared.oomerr);
return C_OK;
}
+
+ /* Save out_of_memory result at script start, otherwise if we check OOM
+ * untill first write within script, memory used by lua stack and
+ * arguments might interfere. */
+ if (c->cmd->proc == evalCommand || c->cmd->proc == evalShaCommand) {
+ server.lua_oom = out_of_memory;
+ }
}
/* Make sure to use a reasonable amount of memory for client side
diff --git a/src/server.h b/src/server.h
index dbd72281f..f37fe4b12 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1392,6 +1392,7 @@ struct redisServer {
execution. */
int lua_kill; /* Kill the script if true. */
int lua_always_replicate_commands; /* Default replication type. */
+ int lua_oom; /* OOM detected when script start? */
/* Lazy free */
int lazyfree_lazy_eviction;
int lazyfree_lazy_expire;