AdvancedBan icon indicating copy to clipboard operation
AdvancedBan copied to clipboard

Database Queries on the Main Thread

Open A248 opened this issue 4 years ago • 1 comments

Applies To Single servers / Bukkit servers

How to Enable the Situation / Reproduce the Bug

  1. A banned player logs in
  2. AdvancedBan queries the user's ban and cancels the log-in event (AsyncPlayerPreLoginEvent)
  3. Another plugin un-cancels the log-in event
  4. Yet another plugin makes the player chat (via the Player#chat function)
  5. The chat event is fired on the main thread
  6. The banned user's possible mute is not cached
  7. AdvancedBan runs a database query to check whether the mute exists

This scenario has a few requirements:

  • If the user is not banned, their data is cached, and therefore when the chat event is called, no database query is made.
  • If no plugin makes the player chat, chat events happen asynchronously, so database queries do not slaughter performance.

Some plugins might un-cancel the log-in event, however unwise that is. Many plugins have the feature to make a player chat. Some chat plugins can even make this happen for normal player chat.

Add any additional information below. Timings may indicate that a user is experiencing this bug. image

A248 avatar Feb 05 '21 01:02 A248

Here is another scenario which is more common, and lifts one of the requirements of the last scenario:

  1. A banned player logs in
  2. AdvancedBan queries the user's ban and cancels the log-in event (AsyncPlayerPreLoginEvent)
  3. Another plugin un-cancels the log-in event
  4. The player runs a command. The command event is fired on the main thread
  5. AdvancedBan runs a database query to check whether the player is muted

So really, there is only 1 requirement for database queries to be made on the main thread:

  • There must be a plugin which un-cancels the log-in event after AdvancedBan has determined the user is banned

Thanks to Sheidy for pointing this out

A248 avatar Feb 05 '21 01:02 A248