skyrim-multiplayer / skymp

Multiplayer Mod & TypeScript SDK for Skyrim Special Edition
Other
221 stars 75 forks source link

[Bug]: HttpClient.post returns an invalid HttpResponse #2214

Open mysticfall opened 1 week ago

mysticfall commented 1 week ago

Severity

Critical. A critical defect that causes some key functionality to fail.

Priority

High. Anything that impacts the typical user flow or blocks app usage.

Description

When I invoke an HTTP API using Skyrim Platform's HttpClient.post, it returns an invalid HttpResponse object in its callback with a status code of 0 and an empty body.

The request reaches the server with the correct information, and the server I tested with correctly responds with a 200 status code and a plain text message, which the client fails to retrieve.

It seems to work as expected on rare occasions, but I've failed to reproduce it reliably so far. HttpClient.get seems to work fine, in comparison.

OS

Linux

OS version

Manjaro/KDE/Wayland

Skyrim version

1.6.1170

SKSE version

2.2.6

client commit''s hash

(Skyrim Platform 2.9.0 Release)

server commit''s hash

N/A

Videocard model

NVidia RTX3080

Steps to reproduce

Here's a snippet of the code that shows the issue:

const http = new HttpClient("http://127.0.0.1:3001")

const payload = { // some JSON data }

http.post("/api/generate", {contentType: "application/json", body: JSON.stringify(payload)}, ).then(res => {
    // This prints "Status: 0, Error: , Body: " most of the times:
    printConsole(`Status: ${res.status}, Error: ${res.error}, Body: ${res.body}`)
})

Expected result

See the above example.

Actual result

See the above example.

mysticfall commented 6 days ago

After a bit more testing, I have a feeling that it might not have to do with post or get but with the timeout. If the server takes too long to respond, the client seems to return prematurely without an error.

I need more tests to confirm this behaviour. But in this case, a configurable timeout option with the promise failing upon exceeding the specified value could be nice.