/* This is the Lua script "count" hook that we use to detect scripts timeout. */
/* This is the Lua script "count" hook that we use to detect scripts timeout. */
voidluaMaskCountHook(lua_State*lua,lua_Debug*ar){
voidluaMaskCountHook(lua_State*lua,lua_Debug*ar){
long long elapsed;
longlongelapsed=mstime()-server.lua_time_start;
UNUSED(ar);
UNUSED(ar);
UNUSED(lua);
UNUSED(lua);
elapsed = mstime() - server.lua_time_start;
/* The conditions to timeout are:
if (elapsed >= server.lua_time_limit && server.lua_timedout == 0) {
* 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);
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;
server.lua_timedout=1;
/* Once the script timeouts we reenter the event loop to permit others
/* Once the script timeouts we reenter the event loop to permit others