mojira.dev
BDS-19922

server.net module not working as expected on Linux

Not sure if this is an issue related to just the newest version, or if it effects older versions as well. I just encountered this issue when creating a new addon.

Basically I created an addon that uses the server.net module for the scripting API, which sends a HTTP post request to a web server I have running locally when a player leaves or joins the server. I have tested the addon on the Windows version on BDS (Test Server) and it worked perfectly. Comes time to add it to the live server I have running on Linux, and I have issues.

 

The server console tells me that the addon has loaded sucessfully, and most functions of the addon work perfectly fine. The issues start when this line of code is run.

const response = await http.request(req);

Which is the line that sends the HTTP post request to the web server. Here is the whole function

 
async function logPlayerJoinOrLeave(player, totalOnline, connectOrDisconect) {
    try {
        let responseBody = "API calls quota exceeded! maximum admitted 1 per 3s.";
                   
            // Ensure that 'players' and 'key' are not undefined or empty
            if (!players || !players.length) {
                console.error("Error: 'player' field is missing or empty.");
                return; // Exit if players is missing or empty
            }
 
            const key = "XXXX";  // Make sure to replace with a valid key if needed
            if (!key) {
                console.error("Error: 'key' field is missing.");
                return; // Exit if key is missing
            }
    var URL = 'http://xxx.xxx.x.xxx:xxxx/LogPlayerActivity?player=' + player + '&totalOnline=' + totalOnline + '&connectOrDisconect=' + connectOrDisconect + '&key=' + key;     
            URL = URL.replace(/\s+/g, '%20');           
            const req = new HttpRequest(URL);      
            req.method = HttpRequestMethod.Post;
            req.headers = [
                new HttpHeader('accept', 'text/plain'),
            ];
                      
            // Await the request and log the response or error
            ***//const response = await http.request(req);***
            responseBody = response.body
           
 
            if(responseBody == "API calls quota exceeded! maximum admitted 1 per 3s."){               
                server.system.runTimeout(() => {
                    logPlayerJoinOrLeave(player, totalOnline, connectOrDisconect)
                }, 3000);
            }
                
    } catch (error) {
        console.error("Request failed:", error); // More detailed error logging
    }
}
This is the event listener that triggers the above function

world.afterEvents.playerJoin.subscribe(e => { 
    var player = e.playerName
    var totalOnline = world.getAllPlayers().length + 1;  
    var connectOrDisconect = true   
    logPlayerJoinOrLeave(player, totalOnline, connectOrDisconect)   
})

When I uncomment the offending line, when a player joins the server their game hangs on "locating server". The console says the player has connected and spawned in, and if they click "cancel" or close the game the console shows them disconecting. If I try to stop the server using the "stop" command after a player attempted to connect, the server also hangs and I have to force close it. And no, the HTTP post request never goes through.

 

Not sure if this is a known bug or if there is a work around, but for now I am not logging player connects or disconnects. I am assuming this is some form of bug since the above code works flawlessly on the Windows version on BDS.

 

Comments 1

We do not have enough information to reproduce this issue.

Please include the following information to help us understand your problem:

Steps to Reproduce:
1. (Explain what needs to be done for the issue to happen)
2.
3.

Observed Results:
(Briefly describe what happens)

Expected Results:
(Briefly describe what should happen)

Please also attach any needed commands, add-ons/behavior packs, data packs, resource packs, screenshots, videos, or worlds needed to help reproduce this issue.

Refer to the Bug Tracker Guidelines for more information about how to write helpful bug reports. Bug reports with insufficient information may be closed as Incomplete.

This issue is being temporarily resolved as Awaiting Response. Once the requested information has been delivered, the report will be reopened automatically.

Quick Links:
📓 Bug Tracker Guidelines – 📧 Mojang Support (Technical Issues) – 📧 Microsoft Support (Account Issues)
📓 Project Summary – ✍️ Feedback and Suggestions – 📖 BDS Wiki – 📖 FAQs

Tyler

(Unassigned)

Unconfirmed

Retrieved