Open katrinafyi opened 1 month ago
After poking in Wireshark, I can't find a discrepancy. The Python is sending the handshake and ping packet correctly. The server is closing the connection without sending any bytes, and the Python is handling that closure.
can reproduce
Is a status packet required before ping? Wiki.vg says no, but performing a status first in the connection seems to fix it. I don't know if this caused by the protocol or a socket bug in mcstatus.
Apparently, we already saw this bug in https://github.com/py-mine/mcstatus/pull/491. worth looking for why it wasn't already fixed on the server implementations side
Not closing this, because we should probably add a note to docs about this.
I see, would it be a good idea to implement ping in using status, then? Maybe ping can automatically fallback to status.
I imagine this is what the vast majority of users would prefer. For ping purposes, you could abort the connection after reading the status response ID to avoid deserialising the whole response.
Closing as a duplicate of #491 Use latency from status object or your own timings as a workaround. We are not able to help with all the non-vanilla implementations behave differently.
I don't see a point in clinging onto a function that works on only a fraction of active servers? Regardless of technical correctness, this is a disaster for the user experience, and at the very least needs an easily discoverable warning.
I do agree that we can add a note/warning to the ping
docstring, as it can be weird to users that it doesn't work when the server is up and status does work. However, this really is an issue with the upstream server implementations. It is them who don't follow the spec properly.
Making an additional status request before ping is very wasteful from our side and using status packet instead of ping for the ping method makes no sense, at that point, just use status
. At most, we could add a bool arg that would make this extra status request in ping, ignore it and then perform ping. But I don't love that idea.
We already manually count the time it took for the server to respond when you're using status
, so you can just use the latency
parameter from that if you need it.
We could also consider deprecating ping
entirely and just keeping status, considering it contains the latency anyways.
I'd support implementing ping() entirely in terms of a status packet. I don't see a need to remove ping(), introducing a breaking change and pushing this task onto every user of the library.
With an implementation as status().latency
, the basic ping would depend on the well-formedness of the status response which might not be desirable. This is why I suggested ping() sends a status packet but ignores the data payload of the response, thus acting in a different way to status().latency
.
Finally, there is a rare possibility, mentioned in https://github.com/py-mine/mcstatus/pull/491#issuecomment-1440484840, where a server might support ping but not status. It would be useful to keep the real ping accessible for such cases (either through a flag or different method name).
Personally, I think performing an automatic fallback (try ping, then status) would be best. This would allow you to print an informative warning if the first ping fails, so users know to file an issue with the server software. I don't feel strongly about fallback vs only using status, however.
Reopening this, since discussion is not over and we definitely have to add a note/warning to docs about this.
Anyway, I agree with ItsDrike, it's server implementations who don't follow the spec, and appropriate bug report should be opened at their repos. ping()
is designed to be as simple as possible, and there is no need to over design it with status()
.
You could even re-raise the OSError with more informative/friendly error text which would put the information somewhere users will definitely see.
Yeah, that is even better solution. If I won't forget, I will create a PR for this
I also agree it would be wasteful to request full status from the server and not use it, hence ping should be separate and standalone. Adding the documentation tag for this, but I have concern that this particular OSError is indistinguishable from legitimate cases where the server crashes or a firewall drops the response.
Sure, you could report to the user "if ping
fails but status
succeeds, it is likely .....".
You can check against error message
ping
doesn't seem to work for any servers I've tested, most of which return:For example:
Note, this was tested through the CLI but I can't see why it would be CLI specific.