Skip to content

Immediate crash when using Global:HttpRequest #265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dewmguy opened this issue Feb 25, 2025 · 7 comments
Open

Immediate crash when using Global:HttpRequest #265

dewmguy opened this issue Feb 25, 2025 · 7 comments

Comments

@dewmguy
Copy link

dewmguy commented Feb 25, 2025

this script used to work perfectly prior to a recent update in acore and/or mod-eluna

currently on AzerothCore rev. 8f6d651471ee 2025-02-24 02:36:22 -0300 (master branch) (Unix, RelWithDebInfo, Static)

function sendDiscordNotification(player, actionType, actionDetail)
    local webhookUrl = "https://discord.com/api/webhooks/redacted"
    local playerName = player:GetName()
    local playerLevel = player:GetLevel()
    local playerClassEmoji = Classes[player:GetClass()] or ":question:"
    local playerFactionEmoji = GetPlayerFaction(player)
    local baseMessage = string.format("%s %s **%s**", playerFactionEmoji, playerClassEmoji, playerName)

    if actionType == "login" then
        message = baseMessage .. " has logged in."
    elseif actionType == "logout" then
        message = baseMessage .. " has logged out."
    elseif actionType == "death" then
        message = baseMessage .. string.format(" has been killed by %s!", actionDetail)
    elseif actionType == "murder" then
        message = baseMessage .. string.format(" has been ganked by %s!", actionDetail)
    elseif actionType == "suicide" then
        message = baseMessage .. string.format(" has %s!", actionDetail)
    elseif actionType == "levelUp" then
        message = baseMessage .. string.format(" has reached level **%d**!", actionDetail)
    elseif actionType == "item" then
        message = baseMessage .. string.format(" has found %s!", actionDetail)
    elseif actionType == "achievement" then
        message = baseMessage .. string.format(" has earned the achievement **[%s]**", actionDetail)
    end

    local payload = "content=" .. urlencode(message)

    HttpRequest("POST", webhookUrl, payload, "application/x-www-form-urlencoded", function(status, body, headers)
        if not status == 204 then
            local output = string.format("Failed to send %s notification for %s. Status: %s", actionType, playerName, status)
            print(output)
        end
    end)
end

tested r-o-b-o-t-o script and came to the same conclusion

-- test.lua
-- GET example (prints a random word)
print("loaded test.lua")

HttpRequest("GET", "https://random-word-api.herokuapp.com/word", function(status, body, headers)
    print("Random word: " .. string.sub(body, 3, body:len() - 2))
end)

-- POST example with JSON request body
HttpRequest("POST", "https://jsonplaceholder.typicode.com/posts", '{"userId": 1,"title": "Foo","body": "Bar!"}', "application/json", function(status, body, headers)
    print(body)
end)

-- Example with request headers
HttpRequest("GET", "https://postman-echo.com/headers", { Accept = "application/json", ["User-Agent"] = "Eluna Lua Engine" }, function(status, body, headers)
    print(body)
end)

console output at startup

Feb 25 08:36:34 warcraftserver worldserver[15278]:
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: class_deathknight_skipintro.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: class_reloadammo.lua.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: loaded joke.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: player_cdresetondeath.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: player_enchantbuyback.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: player_levelpurchase.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: player_skillpurchase.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: server_player_autotrainer.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: server_player_levelrewards.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: server_player_logout.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: Eluna loaded script: server_questskipper.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: loaded test.lua
Feb 25 08:36:34 warcraftserver worldserver[15278]: [Eluna]: HTTP request error: Connection timed out
Feb 25 08:36:34 warcraftserver worldserver[15278]:
Feb 25 08:36:34 warcraftserver systemd[1]: worldserver.service: Main process exited, code=killed, status=11/SEGV
Feb 25 08:36:34 warcraftserver systemd[1]: worldserver.service: Failed with result 'signal'.
Feb 25 08:36:34 warcraftserver systemd[1]: worldserver.service: Consumed 1min 4.864s CPU time.
@55Honey
Copy link

55Honey commented Feb 25, 2025

Please provide a crashlog.

@dewmguy
Copy link
Author

dewmguy commented Feb 26, 2025

I'm not familiar with the location of a crash log, can you point me where to look to provide what you're looking for?

@55Honey
Copy link

55Honey commented Feb 26, 2025

It depends.
On Windows after compiling in RelWithDebInfo you will have a folder with a crashlog file per crash.
On Linux you need to attach a debugger, see https://www.azerothcore.org/wiki/how-to-restart-and-debug#how-to-restart-and-debug

@dewmguy
Copy link
Author

dewmguy commented Mar 1, 2025

so after spending hours rebuilding my server by using the acore dashboard tools and setting up services and figuring out how to build with RelWithDebInfo, the issue is not repeatable.

it's hard to tell whether there's an issue during compilation between Release and RelWithDebInfo, because when I run Release the game crashes using HttpRequest, we just don't get the crash report data you're asking for.

my script and all test scripts work perfectly when running RelWithDebInfo build and compile.

using ubuntu server 22.04, for the record.

@kissingers
Copy link

kissingers commented Mar 11, 2025

I have also encountered multiple crashes, mainly when using the "reload eluna" command. when the http Request is in progress, reload eluna will case crash

@kissingers
Copy link

kissingers commented Mar 11, 2025

https://pastebin.com/s8b355C6
I try a crash for the httpRequest gdb log, might eluna need check if the tcp still online when call back function(status, body, headers), otherwise the data write to wrong ram position so carsh.

local requestBody = JSON.encode({
	model = NowAI.model,
	messages = {
		{role = "system", content = "You are a wow game player"},
		{role = "user", content = m}
	},
	max_tokens = 200, 
	temperature = NowAI.temperature
})

HttpRequest("POST", NowAI.URL, requestBody, "application/json", {["Authorization"] = "Bearer " .. NowAI.key},
    function(status, body, headers)
		if not status or not body then return end
        if status == 200 then
            local ok, response = pcall(JSON.decode, body)
			if ok and response and response.choices and response.choices[1] and response.choices[1].message and response.choices[1].message.content then
                AIRespond = response.choices[1].message.content
				AIRespond = AIRespond:gsub("\n", " "):gsub("%s+", " ")
            end
		else
			AIRespond = "nothing"
        end
		local Tmpplayer = GetPlayerByGUID(playerGUID)
		if Tmpplayer then
			Tmpplayer:SendBroadcastMessage(AIRespond))
		end
    end
)

@mostlynick3
Copy link

Should HTTP requests possibly be added to #269 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants