Velocity icon indicating copy to clipboard operation
Velocity copied to clipboard

Player's game (1.16.5) crashes when attempting to .fireAndForget()

Open nathan-i-martin opened this issue 1 year ago • 4 comments

Capture PNG

Greetings, I've run into an exception and I might be wrong but I think this is a legitimate issue. Velocity server version: 3.1.2-SNAPSHOT build 179 Proxy server is running online-mode. Backend servers are not (ofc). Am using modern player-info-forwarding-mode. The Paper sub-server is running Paper 1.16.5. Build 794

What is happening? When I issue a .fireAndForget() request. The player makes it to the Joining World... screen. But shortly after; the screen changes to Saving World... at which case my game (Minecraft Java 1.16.5) freezes and crashes. The error that popups in the Minecraft client links to here: https://bugs.mojang.com/browse/MC-23484

What do I think is causing it? Unfortunately, the exception didn't give me much info. Additionally, I'm not very knowledgeable in how Minecraft connections work (hence why I wanted to use .fireAndForget().) But I looked in https://github.com/PaperMC/Velocity/blob/6547ccaa7e631ba0a77ff6dd0bf679c1bf960327/proxy/src/main/java/com/velocitypowered/proxy/connection/client/ConnectedPlayer.java And noticed how .connectWithIndication() which is basically the real name of .fireAndForget() says // TODO: The exception handling from this is not very good. Find a better way. Fair enough. However, even if the exception was handled properly, it's still an exception. Which means that something must be going wrong! Do we have any knowledge of a known error inside of this general area of code? I will note. That the RegisteredServer that I'm using .connectWithIndication() on; has been registered by my own plugin and not via the Velocity config. However, I doubt this would cause any issues considering the connection is going through (I see the player join message on the Paper server that I'm trying to join into. It's just that my game freezes and then crashes.) Is it possible that maybe some sort of connection "finalization" packet isn't getting sent which just causes the Minecraft client to just sit and wait for something to happen?

What have I tried? Honestly nothing. I seriously am not super knowledgeable in the Minecraft connection world. I found the issue yesterday and was working on finding the code for the method so I could see if there was anything obvious I should check out. I think I'm going to try copying some of the connection code from the repository and see if I'm able to get an Exception that actually explains more about what is happening.

I also have not tried implementing what I need using .connect() that will probably be the first thing I try after writing this. But even if .connect() works, that doesn't change that for some reason .connectWithIndication() is not.

Also my actual code block I'm using to connect:

player.createConnectionRequest(server.getRawServer()).fireAndForget();
// OR
player.createConnectionRequest(server.getRawServer()).connectWithIndication();

.getRawServer() is returning a RegisteredServer.

Finishing up

Hopefully, this has been enough information to give you an idea of the issue! Generally speaking, I don't really open Issues. But the thing that convinced me to do so was how my client was completely crashing as a result of whatever the Exception is. Even if something I setup wasn't totally correct, it shouldn't result in someone's client crashing. At least I don't think so :) Hopefully, we can find a resolution to this issue! If I find anything I'll post an update!

(Screenshot taken from my Velocity server's console)

nathan-i-martin avatar Sep 08 '22 21:09 nathan-i-martin

I am nearly positive this is an issue on your end. The exception thrown is an IOException indicating your connection was improperly forcefully closed by the client, rather than the server. Since the server is running a supported setup I am fairly certain you do have a Minecraft unrelated issue as pointed out in that Mojira issue report. Try to reproduce this with another computer please

Xernium avatar Sep 09 '22 03:09 Xernium

It seems you might be right! To an extent anyways. It's really late here atm so I can't test on another computer at this exact moment (will do that tomorrow). However, I can say. When I tried joining the network in 1.19.2 it worked! (The Paper servers are still running 1.16.2 I just threw ViaVersion on them so that I'd be able to join in a newer version.)

Additionally, since I posted this issue. I've changed my connection code from the .fireAndForget() method to: ConnectionRequestBuilder connection = player.createConnectionRequest(server.getRawServer()); connection.connect().whenCompleteAsync((status, throwable) -> { VelocityRustyConnector.getInstance().logger().log("connected!!!!!"); VelocityRustyConnector.getInstance().logger().error("",throwable); });

Which, when I tried joining 1.16.5 would still give me the exact same issue as .fireAndForget(). Your note about improperly closing is def a good point. When my client froze one of the first times, I tried letting it just sit and chill for a few minutes and nothing happened. As such, I came to the conclusion that it wouldn't be coming back, and ever since I've just force-closed it.

I'll note that I've also tried joining on 1.18.2. However, my game freezes on the "Loading Terrain..." screen. Maybe with all the chat signing and, I'm sure other things that were probably added in 1.19.2. Maybe using the newer version of the API (3.1.1) for legacy (pre-1.19.2) plugins causes some sort of conflict???? That's just a totally random guess

As you said, until I can test it on some other computers this is just a single, isolated incident. But I figured I'd share a quick update in the meantime.

Either way I appreciate your help! I'll test this out and get my findings back to you ASAP!

nathan-i-martin avatar Sep 09 '22 04:09 nathan-i-martin

IMG_0189 Okay! So I've gotten to test this on two other systems! The results are, both good, but also bad. It seems as tho you're correct, the only computer having this issue is my desktop. This is good because it means the code is working! However, It's bad because now I have literally no idea what the issue is. I find it strange that my system, one with 32GB of RAM and a Ryzen 7 2700X (I.e. it's a pretty decent system) is totally crapping the bed. When these laptops which are between 6 and 13 years old handle it just fine (laggy, but it works)

Is there any way you know of how I can go about seeing what's happening? Anyway, I could look at the crash stack trace for Minecraft or anything? I'd be able to sleep a lot better if I knew what exactly is causing this issue.

I'll also note that, when joining servers in 1.16.5 and other versions, I've never had any issues with this on my desktop. It's only when I join this particular one that uses the custom connection code which I find strange. Regardless, I think you're right in that Velocity is not the issue. At least, not in the way I had anticipated. Could you possibly send me a link to the method that Velocity normally uses to route players into the default server that's defined in velocity.toml? I think I might be able to gleam some information from that.

nathan-i-martin avatar Sep 09 '22 15:09 nathan-i-martin

Regardless of the particular details of the issue you are running into, fireAndForget() should be handling exceptions on the server's side by using an exceptionally block or similar construct. I.e., it should be:

    @Override
    public void fireAndForget() {
      connectWithIndication().exceptionally((ex) -> {
        logger.error("Exception while connecting with indication", ex);
        return null;
      });
    }

See also previous issues #376, #446, #455

A248 avatar Sep 22 '22 02:09 A248