This is the Lua script "count" hook that we use to detect scripts timeout. */
| 1458 | |
| 1459 | /* This is the Lua script "count" hook that we use to detect scripts timeout. */ |
| 1460 | void luaMaskCountHook(lua_State *lua, lua_Debug *ar) { |
| 1461 | long long elapsed = elapsedMs(server.lua_time_start); |
| 1462 | UNUSED(ar); |
| 1463 | UNUSED(lua); |
| 1464 | |
| 1465 | /* Set the timeout condition if not already set and the maximum |
| 1466 | * execution time was reached. */ |
| 1467 | if (elapsed >= server.lua_time_limit && server.lua_timedout == 0) { |
| 1468 | serverLog(LL_WARNING, |
| 1469 | "Lua slow script detected: still in execution after %lld milliseconds. " |
| 1470 | "You can try killing the script using the SCRIPT KILL command. " |
| 1471 | "Script SHA1 is: %s", |
| 1472 | elapsed, server.lua_cur_script); |
| 1473 | server.lua_timedout = 1; |
| 1474 | blockingOperationStarts(); |
| 1475 | /* Once the script timeouts we reenter the event loop to permit others |
| 1476 | * to call SCRIPT KILL or SHUTDOWN NOSAVE if needed. For this reason |
| 1477 | * we need to mask the client executing the script from the event loop. |
| 1478 | * If we don't do that the client may disconnect and could no longer be |
| 1479 | * here when the EVAL command will return. */ |
| 1480 | protectClient(server.lua_caller); |
| 1481 | } |
| 1482 | if (server.lua_timedout) processEventsWhileBlocked(); |
| 1483 | if (server.lua_kill) { |
| 1484 | serverLog(LL_WARNING,"Lua script killed by user with SCRIPT KILL."); |
| 1485 | |
| 1486 | /* |
| 1487 | * Set the hook to invoke all the time so the user |
| 1488 | * will not be able to catch the error with pcall and invoke |
| 1489 | * pcall again which will prevent the script from ever been killed |
| 1490 | */ |
| 1491 | lua_sethook(lua, luaMaskCountHook, LUA_MASKLINE, 0); |
| 1492 | |
| 1493 | lua_pushstring(lua,"Script killed by user with SCRIPT KILL..."); |
| 1494 | lua_error(lua); |
| 1495 | } |
| 1496 | } |
| 1497 | |
| 1498 | void prepareLuaClient(void) { |
| 1499 | /* Select the right DB in the context of the Lua client */ |
nothing calls this directly
no test coverage detected