summaryrefslogtreecommitdiff
path: root/src/scripting.c
diff options
context:
space:
mode:
authorsrzhao <srzhao@sysnew.com>2020-01-20 21:17:02 +0800
committersrzhao <srzhao@sysnew.com>2020-01-20 21:34:05 +0800
commit38f6207f884f514e928513acb6560fdb375daa2e (patch)
tree19724330415bfeb7fee0fe522300ffd0b080b594 /src/scripting.c
parent7ef2270ee73e75b00b0c1bde40fb1df55c7ec6ff (diff)
downloadredis-38f6207f884f514e928513acb6560fdb375daa2e.tar.gz
Check OOM at script start to get stable lua OOM state.
Checking OOM by `getMaxMemoryState` inside script might get different result with `freeMemoryIfNeededAndSafe` at script start, because lua stack and arguments also consume memory. This leads to memory `borderline` when memory grows near server.maxmemory: - `freeMemoryIfNeededAndSafe` at script start detects no OOM, no memory freed - `getMaxMemoryState` inside script detects OOM, script aborted We solve this 'borderline' issue by saving OOM state at script start to get stable lua OOM state. related to issue #6565 and #5250.
Diffstat (limited to 'src/scripting.c')
-rw-r--r--src/scripting.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 9282b7fd9..5ed24ffad 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -655,12 +655,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;