TFS 1.X+ Server Crash...Or maybe not?

Ramirow

Active Member
Joined
Aug 22, 2009
Messages
445
Best answers
10
Likes
156
Location
Argentina
#1
Hello everyone, I'm facing an strange issue with my server, running TFS 1.2
Sometimes, when I login within my local network or some player (from the internet) logs in WHILE im online, the server just hangs.
No error code, the console just stays open but everyone gets Connection Lost and server basically closes.

What I did:
Thought that I was something with the player, after restarting server he just logged in fine.
After that, thought it was something caused by login itself. Tried to logout and login more than 100 times with no luck.

It happens sometimes, and sometimes it doesn't, what could possibly be? Or what additional data I need to have for you guys to help me identify the issue? Thanks in advance!
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#3
if the server hangs it's caused by an infinite loop, which most likely means it's a script unless you've made recent source changes
like bogart said, it's most likely a login script you have in creaturescripts but it could also be some new system you added which has a loop with a condition that can result in an infinite loop
 

Ramirow

Active Member
Joined
Aug 22, 2009
Messages
445
Best answers
10
Likes
156
Location
Argentina
#4
Hmmm...my login script is the following:
Code:
function onLogin(player)
    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end
        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("statHP")
    player:registerEvent("dragonKill")
    player:registerEvent("cycKill")
    player:registerEvent("boneKill")
    player:registerEvent("rotKill")
    player:registerEvent("wolfKill")
    player:registerEvent("spiderKill")
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    return true
end
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#5
Hmmm...my login script is the following:
Code:
function onLogin(player)
    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end
        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("statHP")
    player:registerEvent("dragonKill")
    player:registerEvent("cycKill")
    player:registerEvent("boneKill")
    player:registerEvent("rotKill")
    player:registerEvent("wolfKill")
    player:registerEvent("spiderKill")
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    return true
end
go to data/global.lua and put this code at the bottom:
Lua:
local start = os.mtime()
local linecount = 0
debug.sethook(function(event, line)
    linecount = linecount + 1
    if os.mtime() - start >= 1000 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.mtime()
    end
end, "l")
now when you have a possible infinite loop somewhere in your code it will print out something like this
Code:
possible infinite loop in file @data/global.lua near line 80
you just have to wait for it to hang again, if nothing pops up in the server after a few seconds then it's related to source and not a script
 
Last edited:

Ramirow

Active Member
Joined
Aug 22, 2009
Messages
445
Best answers
10
Likes
156
Location
Argentina
#6
Thank you sir! I have already inserted the code, got a similar message after starting the server:

Code:
possible infinite loop in file @data/npc/lib/npc.lua near line 2
That line contains:
Code:
dofile('data/npc/lib/npcsystem/npcsystem.lua')
I think I can ignore that event as my issue arises at login, I don't see how an NPC file could affect that, I will just wait now!
 

Stigma

Well-Known Member
Joined
Feb 14, 2015
Messages
4,363
Best answers
356
Likes
1,938
#7
change >= 30000 to >= 500000 so it's less likely to give a false positive, if you still get false positives change it to higher
the highest line count i've tested was 1million
 
Top