[ANY TFS] Catch scripts that freeze server

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,554
Reaction score
2,104
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.mtime() - 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 by a moderator:

Fresh

Quack!
Joined
Oct 21, 2009
Messages
1,550
Reaction score
140
Location
Poland
Oh my god! That guy is supa dupa amazing!
I wish to give him +rep and follow~
 
OP
Stigma

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,554
Reaction score
2,104
says any tfs in the title
 

Shadow_

Premium User
Premium User
Joined
Jun 2, 2018
Messages
362
Reaction score
73
Location
Cairo, Egypt
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
 

Awesomedudei

Revolutionot.com
Joined
Jan 20, 2010
Messages
266
Reaction score
36
Location
Sweden
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 :/
 
Top