chatterino2 icon indicating copy to clipboard operation
chatterino2 copied to clipboard

Introduce HTTP API for plugins

Open Mm2PL opened this issue 9 months ago • 3 comments

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

Mm2PL avatar May 06 '24 21:05 Mm2PL

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 avatar May 07 '24 21:05 Mm2PL

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.

Mm2PL avatar May 08 '24 23:05 Mm2PL

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

pajlada avatar May 11 '24 10:05 pajlada