• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[ANY TFS] Catch scripts that freeze server

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,643
Solutions
559
Reaction score
3,948
put this code in a lib file (global.lua if tfs 1.x):
Lua:
local start = os.time()
local linecount = 0
debug.sethook(function(event, line)
    linecount = linecount + 1
    if os.time() - start >= 1 then
        if linecount >= 30000 then
            print(string.format("possible infinite loop in file %s near line %s", debug.getinfo(2).source, line))
            debug.sethook()
        end
        linecount = 0
        start = os.time()
    end
end, "l")

example output:
Code:
possible infinite loop in file @data/global.lua near line 83

reason: i forced this infinite loop to hang server
Lua:
local i = 1
while true do
    i = i + 1
end

if this script is producing false positives, change linecount >= 30000 to linecount >= 1000000, there should be no way other than an infinite loop to produce 1,000,000 line executions in 1 second
 
Last edited:
Oh my god! That guy is supa dupa amazing!
I wish to give him +rep and follow~
 
Code:
Lua Script Error: [Main Interface]
data/global.lua
data/global.lua:22: attempt to index global 'debug' (a boolean value)
[Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua

Not working with tfs 1.3
Its a clean tfs just compiled it
 
Code:
Lua Script Error: [Main Interface]
data/global.lua
data/global.lua:22: attempt to index global 'debug' (a boolean value)
[Warning - ScriptingManager::loadScriptSystems] Can not load data/global.lua

Not working with tfs 1.3
Its a clean tfs just compiled it

Same here :/
 
Apparently this script wasn't working for over a year because I somehow managed to release it after testing and put snuck in an os.mtime() where it shouldn't have been, I updated the script and retested and now it works.

If you get an error with global debug, some script you have is overriding the debug library which is why you should be careful with variable names.
 
Apparently this script wasn't working for over a year because I somehow managed to release it after testing and put snuck in an os.mtime() where it shouldn't have been, I updated the script and retested and now it works.

If you get an error with global debug, some script you have is overriding the debug library which is why you should be careful with variable names.
Thank you!
 
Hello
i am using a table with a script in actions

local config = {
[5555] = xx,
}

using many UIDs
when i use these lines i get warning of infinite loop

local item_uid = config[item.uid]
if item_uid then

what can be the problem with that? And how to avoid infinite loop?
 
Hello
i am using a table with a script in actions

local config = {
[5555] = xx,
}

using many UIDs
when i use these lines i get warning of infinite loop

local item_uid = config[item.uid]
if item_uid then

what can be the problem with that? And how to avoid infinite loop?
based on the code you sent it's a false positive likely from all scripts loading on server start, read the bottom of the original post
 
very nice, how did I missed it? :D btw does it only display one "script" at time?
 
based on the code you sent it's a false positive likely from all scripts loading on server start, read the bottom of the original post
Yes i read it but I didn’t know that could be a false positive.
Thanks for answer.
 
on top of your script i wrote something like this it shows (or should show) scripts that execute longer then 5 ms :)


Lua:
local log_slow_exec_startExecProg = os.clock()
local log_slow_exec_currExecProg = ""

local log_slow_exec_ReportTime = 0.005 -- where 1 is 1 second and 0.005 is 5 ms

-- enable disable this logger
local ExtendedDebug = true

debug.sethook(function(event, line)
    if ExtendedDebug and log_slow_exec_currExecProg ~= debug.getinfo(2).source then
      if log_slow_exec_currExecProg ~= "" then
        local execTime = os.clock() - log_slow_exec_startExecProg
        if execTime > log_slow_exec_ReportTime then
          print(string.format(">>> long file %s executed in %.3f ms", log_slow_exec_currExecProg, execTime*1000))
        end
      end
    end
    if ExtendedDebug and log_slow_exec_currExecProg ~= debug.getinfo(2).source then
      -- init file changed
      log_slow_exec_startExecProg = os.clock()
      log_slow_exec_currExecProg = debug.getinfo(2).source
      -- print ("source changed: " .. log_slow_exec_currExecProg) -- display source file changed for debugging only
    end
end, "l")
 
Back
Top