Skip to content
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

[@minecraft/server-net] Server loop blocks when not including a request body #861

Open
Tracked by #863
ProtocolPav opened this issue Jun 16, 2024 · 0 comments
Open
Tracked by #863

Comments

@ProtocolPav
Copy link

Describe the bug
When I try to send any of POST, PUT, DELETE requests using server-net, if I do not include a request body, the game crashes. I believe the game loop gets blocked since entities stop moving, blocks stop dropping themselves when mined, and I can't even send commands via the console.

To Reproduce
Steps to reproduce the behavior:

  1. Create a script that sends a DELETE request to an API endpoint
  2. Do not include a request body
  3. Notice how entities stop moving
  4. Also, notice on your API access logs that the request never came in

Expected behavior
DELETE request gets sent to the API and you don't crash your server

Screenshots
Console logs. Sends the requests. Notice how there is no response.
image

Changed the script code to include an empty JSON body. Notice the response.
image

Additional context
Simple code that accesses all 4 methods on an endpoint in the API and returns the response body.
Technically, DELETE requests shouldn't even have a request body so I never set one, and was so confused why it would crash.

import { http, HttpHeader, HttpRequest, HttpRequestMethod } from '@minecraft/server-net';

system.run(() => {
    const requests = [
        new HttpRequest(`http://nexuscore:8000/api/v0.1/users/test`).setMethod(HttpRequestMethod.Get),
        new HttpRequest(`http://nexuscore:8000/api/v0.1/users/test`).setMethod(HttpRequestMethod.Put),
        new HttpRequest(`http://nexuscore:8000/api/v0.1/users/test`).setMethod(HttpRequestMethod.Post),
        new HttpRequest(`http://nexuscore:8000/api/v0.1/users/test`).setMethod(HttpRequestMethod.Delete),
    ]

    for (const request of requests) {
        request.body = JSON.stringify({}) // If you do not include this line, POST, PUT and DELETE requests crash the game
        request.headers = [
            new HttpHeader("Content-Type", "application/json"),
            new HttpHeader("auth", "my-auth-token"),
        ];
    
        console.log(request.uri, request.method)
        http.request(request).then((response) => console.log(response.body))
    }
}) 
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

1 participant