itzg / itzg/docker-minecraft-bedrock-server

Unknown errors using `@minecraft/server-net`.

Open
#436 1 comment 0 reactions 0 assignees View on GitHub
discussion
Dominant language
Shell
Stars
1.9k
Forks
303
Avg merge
2h 26m
Merged PRs (30d)
2

Description

# No response, when sending HTTP Request using Script API Inside the docker container.

Hey, recently I have been trying to use Script API to send an HTTP Request to fetch a database inside Minecraft Bedrocks Script API Which is inside a docker container using `itzg/docker-minecraft-bedrock-server`. I know my code works well, as I have used it before outside the docker container. Here is a small snippet of the code here:
```ts
/**
* Sends a request to create a table
* @param tableName
*/
static async createTable(tableName: string): Promise {
try {
const secret = secrets.get("databaseToken");
if (!secret) throw new Error(`[DATABASE]: No database token found!`);

const uri = `${DATABASE_HOST}:${DATABASE_PORT}/api/database/${DATABASE_NAME}/table/${tableName}/create`;
const res = new HttpRequest(uri);
console.log(`[DATABASE] Creating table: ${tableName}, to: "${uri}"!`);
res.setMethod(HttpRequestMethod.Post);
res.setHeaders([new HttpHeader("authorization", secret)]);
const response = await http.request(res);

console.warn(
`[DATABASE]: Table: ${tableName} created, status: ${response.status}!`
);
return response.status;
} catch (error) {
console.warn(`[DATABASE]: Failed to create table: ${tableName}, ${error}!`)
return 404
}
}
```

As you can see, its sending a HTTP Post request to an endpoint and waiting for a response. However, when you look at the logs for the server it says this

```
[2024-07-11 13:01:28:284 INFO] [Scripting] [DATABASE]: Creating new database instance for table: entities!

[2024-07-11 13:01:28:284 INFO] [Scripting] [DATABASE] Creating table: entities, to: "http://host.docker.internal:3000/api/database/testing/table/entities/create"!
```

No response is ever given, and it just stays blank. Additionally, when I go to look at the database logs, nothing has come through. So I am guessing that somewhere the HTTP Request is getting lost or deleted. However when I look at the NGINX logs for my database, it shows that my request getting sent never comes through, but another request with a return of `408` is sent.

`2024-07-11 09:32:02 172.20.0.1 - - [11/Jul/2024:13:32:02 +0000] "POST /api/database/testing/table/entities/create HTTP/1.1" 408 25 "-" "libhttpclient/1.0.0.0"`

I'm very confused with what is going on. I feel like something inside the docker container is blocking it. I know it's not the network because inside my docker-compose I have a proxy system that is able to connect to the database the same way which is using `Go-http-client` as shown below

`2024-07-11 09:29:07 172.20.0.1 - - [11/Jul/2024:13:29:07 +0000] "GET /api/database/testing/table/entities HTTP/1.1" 200 463 "-" "Go-http-client/1.1"`

Please help me figure out whats going on, and if this is something to do with the image.

Contributor guide

Open the contributing guide

Research direction

Start with the docker-compose configuration and the container/server logs described in the report. Reproduce the POST request through @minecraft/server-net, compare the NGINX 408 entry with the successful Go-http-client request, and check whether the container can reach the reported host.docker.internal endpoint. Done means identifying whether the image or container configuration causes the request timeout and documenting the relevant fix or limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, nginx, typescript
Domain
infrastructure, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.