[SPIGOT-3283] Sneaking while a NaN velocity is applied causes hang & crash Created: 01/Jun/17  Updated: 02/Jun/17  Resolved: 02/Jun/17

Status: Resolved
Project: Spigot
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Johnny Joannou Assignee: Unassigned
Resolution: Fixed Votes: 1
Labels: bug, crash, crouching, entity, hang, velocity
Environment:

Spigot: git-Spigot-3fb9445-6e3cec8

Plugins:  Plugins (1): SimplePlugin (For demonstration / reproduction)



 Description   

Perhaps this should be classified as major/private? It can cause a crash pretty easily depending on circumstances.

 

I was able to crash the server by doing the following while crouched:

p.setVelocity(new Vector(Double.NaN, Double.NaN, Double.NaN));

 

Tested on a freshly build Spigot with 0 plugin except for a barebones plugin to set my velocity to NaN. ONLY seems to happen when sneaking? I can't do it any other way, hangs immediately upon setting velocity while crouching.

A typical thread dump from this hang: https://hastebin.com/jigoyutaro.md - Sometimes has a few lines about BlockStairs and whatnot in there as well.

 

Proposed fix:

Adding this to the top of setVelocity in CraftEntity fixes the issue.

if (Double.isNaN(vel.getX())) vel.setX(0);
if (Double.isNaN(vel.getY())) vel.setY(0);
if (Double.isNaN(vel.getZ())) vel.setZ(0);

 

(Maybe set to current velocity if current isn't NaN? I tried doing this without the check and some players reported "Infinite ascension")

Perhaps add some sort of warning or message like the excessive velocity warning, but for NaN velocities?

Without this fix I was crashing 5-10 times a day, with the fix I haven't crashed in the last 72 hours. The cause of the NaN velocities was a misconfigured Mythic Mob, but this can still be an issue for other plugins that aren't safely checking velocities before setting them.



 Comments   
Comment by Johnny Joannou [ 01/Jun/17 ]

Sure, I respect this decision.

Maybe we can leave this open and see if other people may be experiencing a similar issue.

 

It's just pretty easy to accidentally divide by 0 and create a NaN.

Plugins SHOULD be checking for NaN's, but it's easy to overlook, doesn't mean the plugin is terribly coded. (Usually from user input, or just a rare case where something turns to 0 in a specific case)

 

I've created a report on Mojang's side as well, because perhaps they can handle a NaN velocity and not load infinite amounts of chunks. They might just close it and say "Not our problem" though, worth a shot?

https://bugs.mojang.com/projects/MC/issues/MC-118164?filter=allissues

Comment by md_5 [ 01/Jun/17 ]

All I'm saying is it isn't nearly as simple as you make it out to be, as history has indicated.
We have to deal with over a hundred thousand different installs with different use cases, and what is acceptable for you may not be acceptable for all of them, which is why the issue warrants further investigation and not just whacking in a three line fix. The issue isn't major/critical/private because it can only be caused by terribly coded plugins.

Comment by Johnny Joannou [ 01/Jun/17 ]

What I don't get is that setting NaN velocities is equivalent to setting your velocity to 0, it doesn't fling you into deep space, it just kills your velocity.

Except with a NaN velocity, it kills the server if you're crouching.

So doing a NaN check and setting to 0 shouldn't really affect the expected outcome anyways?

Comment by md_5 [ 01/Jun/17 ]

>Please, literally plugins are setting velocities via setVelocity and sometimes it is NaN.

We HAD this fix before (https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/9f071ab402a8cdab804626d58bfc19855e8a8e05) and it was removed because people complained about it:
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/1d2509b99fb10b3bd6f597e63805f85b49d5a055

Turns out lots of plugins are doing this and people hate it when you break plugins that appear to be working even if they ultimately do the wrong thing

Comment by Johnny Joannou [ 01/Jun/17 ]

Please, literally plugins are setting velocities via setVelocity and sometimes it is NaN.

Minecraft isn't handling NaN correctly and it causes a crash.

 

I hate to be shrewd, but it's very difficult to track down all plugins/instances of a NaN setVelocity, else I'm just going to have to keep building a custom version of spigot with this fix.

Comment by Black Hole [ 01/Jun/17 ]

Bad plugins will do bad things. Spigot can't possible validate all the methods plugins might call. Plugins could even directly call the Minecraft internal classes.

Generated at Tue Apr 08 01:20:41 UTC 2025 using Jira 10.3.3#10030003-sha1:d220e3fefc8dfc6d47f522d3b9a20c1455e12b7b.