summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2019-10-02 08:40:35 +0300
committerOran Agra <oran@redislabs.com>2019-10-02 08:40:35 +0300
commit98426e98868e91e8be42849ad13d36ea538ccf25 (patch)
tree3097db4c88204fe3fd9b9a3576ca5316da3f387d
parent40acb4412d9409ef4339d07caeeba540256a062a (diff)
downloadredis-98426e98868e91e8be42849ad13d36ea538ccf25.tar.gz
On LUA script timeout, print the script SHA to the log
since the slowlog and other means that can help you detect the bad script are only exposed after the script is done. it might be a good idea to at least print the script name (sha) to the log when it timeouts.
-rw-r--r--src/scripting.c9
-rw-r--r--src/server.h1
2 files changed, 9 insertions, 1 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 3129e4f47..8ce090e9c 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -1083,6 +1083,7 @@ void scriptingInit(int setup) {
if (setup) {
server.lua_client = NULL;
server.lua_caller = NULL;
+ server.lua_cur_script = NULL;
server.lua_timedout = 0;
ldbInit();
}
@@ -1407,7 +1408,11 @@ void luaMaskCountHook(lua_State *lua, lua_Debug *ar) {
/* Set the timeout condition if not already set and the maximum
* execution time was reached. */
if (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);
+ serverLog(LL_WARNING,
+ "Lua slow script detected: still in execution after %lld milliseconds. "
+ "You can try killing the script using the SCRIPT KILL command. "
+ "script SHA is: %s",
+ elapsed, server.lua_cur_script);
server.lua_timedout = 1;
/* Once the script timeouts we reenter the event loop to permit others
* to call SCRIPT KILL or SHUTDOWN NOSAVE if needed. For this reason
@@ -1524,6 +1529,7 @@ void evalGenericCommand(client *c, int evalsha) {
* If we are debugging, we set instead a "line" hook so that the
* debugger is call-back at every line executed by the script. */
server.lua_caller = c;
+ server.lua_cur_script = funcname + 2;
server.lua_time_start = mstime();
server.lua_kill = 0;
if (server.lua_time_limit > 0 && ldb.active == 0) {
@@ -1550,6 +1556,7 @@ void evalGenericCommand(client *c, int evalsha) {
queueClientForReprocessing(server.master);
}
server.lua_caller = NULL;
+ server.lua_cur_script = NULL;
/* Call the Lua garbage collector from time to time to avoid a
* full cycle performed by Lua, which adds too latency.
diff --git a/src/server.h b/src/server.h
index 6e011a2ca..6f3451eb7 100644
--- a/src/server.h
+++ b/src/server.h
@@ -1389,6 +1389,7 @@ struct redisServer {
lua_State *lua; /* The Lua interpreter. We use just one for all clients */
client *lua_client; /* The "fake client" to query Redis from Lua */
client *lua_caller; /* The client running EVAL right now, or NULL */
+ char* lua_cur_script; /* The current script right now, or NULL */
dict *lua_scripts; /* A dictionary of SHA1 -> Lua scripts */
unsigned long long lua_scripts_mem; /* Cached scripts' memory + oh */
mstime_t lua_time_limit; /* Script timeout in milliseconds */