FragLand / minestat

:chart_with_upwards_trend: A Minecraft server status checker
GNU General Public License v3.0
352 stars 71 forks source link

[Javascript] minestat.online returns True even after server is shut down #130

Closed Conanap closed 1 year ago

Conanap commented 1 year ago

Hello! I have a web server running that displays the status of my minecraft server. Here's the relevant code:

const mcstatus = require('minestat');
...
app.get('/statuses/mc', function(req, res, next) {
    return mcstatus.init('localhost', 25565, function(result) {
        return res.json(mcstatus.online ? "Online" : "Offline");
    });
});

Minecraft server is hosted on localhost on 25565, launched via a batch script:

java -Xmx4096M -Xms4096M -jar server.jar -nogui
pause

When the web server is initialised, and the minecraft server is not, it behaves as expected, reporting that the server is offline. Once I initialise the minecraft server, it also correctly reports ther server is now online. However, once I terminate the bashscript with ctrl+c, and Y to the confirmation dialogue, the status seems to be stuck as online.

I've checked via the minecraft client, and the server is indeed offline.

Let me know if there's any other information I can provide, thanks!

ldilley commented 1 year ago

Thank you for reaching out, @Conanap. I just tested against a Minecraft server running version 1.4.7 with the ternary operator using nodejs v12.22.12. This test was also using the latest minestat.js code from master. I am unable to replicate your findings. See the screenshots below for details. The first instance of "Online" is while the server is running. The "Offline" output that follows is after I terminate the Minecraft server.

Is the variable's value or the result possibly cached in your webserver application (or browser) somehow?

image image

Conanap commented 1 year ago

Hey, thanks for the quick reply! I've refreshed the broswer as well and clear cache, but couldn't seem to get it to show as offline. The site makes a request for the updated status to the server every 10 seconds, and in the networking tab I can see that the response is "online" as well

image

Perhaps the server version may be the issue? Is there support for 1.19.x? Thanks!

ldilley commented 1 year ago

After some discussion and testing with @mindsolve, it turns out that this is a bug if the interpreter is run interactively/persistently. The interpreter retains the true value until it exits (or the variable is explicitly reset). We have a small fix that I'll be pushing soon.

ldilley commented 1 year ago

PR #131 has been submitted as a fix. Please let us know if that resolves your issue, @Conanap. If so, I'll ensure that the npm package gets updated as well.

Conanap commented 1 year ago

Thanks @ldilley! The fix works perfectly. Please give me aheads up if possible when it gets deployed to npm. Many thanks for the prompt fix!

ldilley commented 1 year ago

You are most welcome, @Conanap. I am glad that the latest PR merge resolved your issue. Version 1.0.4 has also been published to the official npm repository.