Chatterino / chatterino2

Chat client for https://twitch.tv
MIT License
1.97k stars 442 forks source link

Introduce HTTP API for plugins #5383

Closed Mm2PL closed 2 weeks ago

Mm2PL commented 2 months ago

This adds a new API: c2.HTTPRequest that requires a new permission: Network.

Mm2PL commented 2 months ago

The crash happens in the handlers of the request. Looking at the captured L, it's probably the thread from c2.later getting deleted while the callbacks hold on to it through lua_State.

I'll have to store an ID of the plugin or something and get the state back then.

Mm2PL commented 2 months ago

The following code segfaults after a short while:

local function send_req()
    local req = c2.HTTPRequest.create(c2.HTTPMethod.Get, "https://postman-echo.com/get")
    req:on_success(function(res)
    end)
    req:on_error(function(result)
    end)
    req:execute()
    c2.later(send_req, 100)
end

send_req()

The crash happens in the handlers of the request. Looking at the captured L, it's probably the thread from c2.later getting deleted while the callbacks hold on to it through lua_State.

Weird that this only happens with hosts that are remote that is have some latency. Seems like a pesky race condition.

pajlada commented 1 month ago

Let me know when it's in a finished state and I'll take a look