[ANY TFS] Catch scripts that freeze server

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
4,916
Best answers
448
Reaction score
2,525
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,569
Best answers
10
Reaction score
165
Location
Poland
Oh my god! That guy is supa dupa amazing!
I wish to give him +rep and follow~
 
OP
Delusion

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
4,916
Best answers
448
Reaction score
2,525
says any tfs in the title
 

adric21

Member
Joined
Apr 26, 2016
Messages
201
Best answers
1
Reaction score
15
@Stigma if its tfs 0.4 where i need paste the code data/libs/???
 

Shadow_

Active Member
Joined
Jun 2, 2018
Messages
408
Best answers
16
Reaction score
93
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
280
Best answers
0
Reaction score
42
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