minecrafter / RedisBungee

The leading player synchronization system for BungeeCord
https://www.spigotmc.org/resources/redisbungee.13494/
Eclipse Public License 1.0
157 stars 122 forks source link

Time discrepancy between machines #20

Closed colinmcdonald22 closed 9 years ago

colinmcdonald22 commented 9 years ago

I've been investigating an issue we've been having regarding one Bungee instance reporting the other Bungees' clocks are behind (Relevant code here). My first reaction was that the time was not synchronized. After doing a few more checks, I realized the clocks are indeed synchronized.

It appears the issue we're having was introduced here (when heartbeats started using nanoseconds instead of milliseconds). Quoting the javadocs (seen here),

This method can only be used to measure elapsed time and is not related to any other notion of system or wall-clock time. The value returned represents nanoseconds since some fixed but arbitrary origin time (perhaps in the future, so values may be negative). The same origin is used by all invocations of this method in an instance of a Java virtual machine; other virtual machine instances are likely to use a different origin.

As stated by the javadocs, System.nanoTime() should not be used for comparing time across multiple machines (or even JVMs, for that matter). Because of this behavior, milliseconds (instead of nanoseconds) should be used in the RedisBungee heartbeat.

This issue should be resolved by reverting commits 195857a531b75fa9bdbd254a04ff28bb4ff70991 and 7c76b245d4dfad728317d291889a5feb684bde2d.

minecrafter commented 9 years ago

Fixed, sorry