summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2018-08-29 18:14:46 +0200
committerantirez <antirez@gmail.com>2018-08-29 18:14:46 +0200
commit17b0d99d9fde0747eb9730c91ad900d9fc53fdba (patch)
tree30b6f8db5a3d1ffa1b440a167a5af44b3e3d939a
parent476eea95dad37aa2c11cd82627926b9d117e052a (diff)
downloadredis-17b0d99d9fde0747eb9730c91ad900d9fc53fdba.tar.gz
Allow scripts to timeout on slaves as well.
See reasoning in #5297.
-rw-r--r--src/scripting.c12
-rw-r--r--src/server.c1
2 files changed, 10 insertions, 3 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 9afc08a94..c3ee0f971 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -1222,12 +1222,18 @@ sds luaCreateFunction(client *c, lua_State *lua, robj *body) {
/* This is the Lua script "count" hook that we use to detect scripts timeout. */
void luaMaskCountHook(lua_State *lua, lua_Debug *ar) {
- long long elapsed;
+ long long elapsed = mstime() - server.lua_time_start;
UNUSED(ar);
UNUSED(lua);
- elapsed = mstime() - server.lua_time_start;
- if (elapsed >= server.lua_time_limit && server.lua_timedout == 0) {
+ /* The conditions to timeout are:
+ * 1. The caller is not our master.
+ * 2. The timeout was reached.
+ * 3. We are not already timed out. */
+ if (!(server.lua_caller->flags & CLIENT_MASTER) &&
+ elapsed >= server.lua_time_limit &&
+ server.lua_timedout == 0)
+ {
serverLog(LL_WARNING,"Lua slow script detected: still in execution after %lld milliseconds. You can try killing the script using the SCRIPT KILL command.",elapsed);
server.lua_timedout = 1;
/* Once the script timeouts we reenter the event loop to permit others
diff --git a/src/server.c b/src/server.c
index 55bcb4dc2..1afc9a802 100644
--- a/src/server.c
+++ b/src/server.c
@@ -2683,6 +2683,7 @@ int processCommand(client *c) {
/* Lua script too slow? Only allow a limited number of commands. */
if (server.lua_timedout &&
+ !(c->flags & CLIENT_MASTER) &&
c->cmd->proc != authCommand &&
c->cmd->proc != replconfCommand &&
!(c->cmd->proc == shutdownCommand &&