• 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!
  • If you're using Gesior 2012 or MyAAC, please review this thread for information about a serious security vulnerability and a fix.

[ANY TFS] Catch scripts that freeze server

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,639
Solutions
559
Reaction score
3,900
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:

Fresh

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

Shadow_

Veteran OT User
Joined
Jun 2, 2018
Messages
1,017
Solutions
31
Reaction score
429
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
425
Solutions
1
Reaction score
190
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 :/
 
OP
OP
Infernum

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,639
Solutions
559
Reaction score
3,900
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.
 

Shadow_

Veteran OT User
Joined
Jun 2, 2018
Messages
1,017
Solutions
31
Reaction score
429
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!
 

mRefaat

Marketing and Coding
Joined
Jan 18, 2014
Messages
832
Solutions
3
Reaction score
130
Location
Egypt
GitHub
MohamedRefaat
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?
 
OP
OP
Infernum

Infernum

Senator
Joined
Feb 14, 2015
Messages
5,639
Solutions
559
Reaction score
3,900
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
 

Evil Puncker

I know nothing
TFS Developer
Joined
May 30, 2009
Messages
8,507
Solutions
260
Reaction score
4,465
very nice, how did I missed it? :D btw does it only display one "script" at time?
 

thesxw

Active Member
Joined
Sep 19, 2015
Messages
39
Reaction score
26
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")
 
Top