Synchronized Code Access - NoLagg

How the cross-thread guard of NoLagg works

A simple introduction and description

Imagine you have a TODO list located on your refrigerator. Now you go to that list, look at it and read it line by line, after which you perform a task. What if a second person stands next to you and removes a line on this TODO list while you are still reading it? Or what if he writes a new line on this list?

This is what happens when two threads try to access the same 'Object' at the same time. This results in something called 'Concurrent Modification Exceptions', which basically means that an object (a collection in this case) got modified while it was expecting this object to stay the same.

The problem is, however, that the wrong plugin can be accused of this error! If the main thread is reading the player list and suddenly another thread removes a player, the main thread spits out that error while the thread that caused this in the first place, is ignored.

This is what NoLagg tackles. Whenever something that is to be called by the main thread ONLY is called by another thread, it logs a warning with all details needed to trace the cause back.

How these errors look like

12:48:39 [WARNING] Could not properly handle event PLAYER_TELEPORT:
java.lang.IllegalAccessError: Synchronized code got accessed from another thread: com.cypherx.xauth.xAuth$2
        at org.bukkit.event.player.PlayerListener.onPlayerTeleport(PlayerListener:0)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:339)
        at org.bukkit.craftbukkit.entity.CraftPlayer.teleport(CraftPlayer.java:297)
        at org.bukkit.craftbukkit.entity.CraftEntity.teleport(CraftEntity.java:156)
        at com.cypherx.xauth.xAuth$2.run(xAuth.java:302)
        at org.bukkit.craftbukkit.scheduler.CraftWorker.run(CraftWorker.java:34)
12:48:39 [INFO] This error is logged only once: it could have occurred multiple times by now.
12:48:40 [INFO] Please contact one of the authors of plugin 'xAuth': CypherX

Looking at the stack trace reveals the thread that caused this:

at com.cypherx.xauth.xAuth$2.run(xAuth.java:302)

In this case, xAuth is acting up and is currently causing that issue. It's now up to the author of this plugin to resolve his mistake. These errors are only thrown once: it is possible that this error was thrown hundreds and hundreds of times. This can affect all other plugins dramatically: if you get a 'concurrent modification exception' or 'Array index out of range exception' in another plugin right after this error, then first check out the plugin that caused the synchronized code access error.


Comments

  • To post a comment, please or register a new account.
Posts Quoted:
Reply
Clear All Quotes