mastercake10 / uShop

A simple shop plugin for selling items
GNU General Public License v3.0
3 stars 8 forks source link

Bug with uShop 2.2.0 #20

Closed itsgaryk closed 11 months ago

itsgaryk commented 4 years ago

What steps will reproduce the issue?

  1. One player enters /sell
  2. Another player enter /sell

What was supposed to happen?

It should display the total value of items It should return the items if added to the sell box and the user cancels

What happened instead?

It shows value $0 for items of any quantity It does not return the items

What version of this plugin are you using?

2.2.0

What Spigot version are you using? Paste the output of /version below.

PaperMC build 130

What plugins do you have installed? Paste the output of /plugins below.

BackupOnEvent, ConsoleSpamFix, DeadChest, DiscordSRV, DropHeads, dynmap, Essentials, EssentialsChat, EssentialsSpawn, GriefPrevention, InstantBreak, LuckPerms, Pingas, PlugMan, ProtocolLib, SilkSpawners, SmoothSleep, uShop, Vault, WorldEdit

Are any errors related to this plugin in your console or logs? If so, paste below.

No visible errors

Any additional information that you would like to provide that may be relevant to the issue?

The bug can be reproduced after restarting the server. See the below image. image

itsgaryk commented 4 years ago

I believe the same issue has been raised, however they have not mentioned items failing to return to the player https://github.com/mastercake10/uShop/issues/18

kotarobo commented 4 years ago

I'm seeing the same problem. I've also observed a deadlock and thread proliferation after that glitch occurred. The stack trace shows the following My server crashes when it grows by about 30,000.

`"Craft Scheduler Thread - 21152" #149360 prio=5 os_prio=0 tid=0x00007f2e730db970 nid=0xc2f7 waiting for monitor entry [0x00007f2c55ab7000] java.lang.Thread.State: BLOCKED (on object monitor) at xyz.spaceio.ushop.Main.lambda$0(Main.java:82)

MellnasMellicia commented 4 years ago

I believe the following code is the source of the problem? src/xyz/spaceio/ushop/Main.java(Line 298) this.getOpenShops().put(p, inv); This code changes the HashMap, but the Because it is not synchronized, a ConcurrentModificationException is thrown. In that case, the iterator needs to be regenerated, but since it was created outside of a while statement, it looks like an infinite loop of calling next(), throwing ConcrrentModificationException, continue, next().... Also, synchronized is not released from another thread, so it's a deadlocked state. I think this is also the reason why a lot of threads are created and not released.

mastercake10 commented 4 years ago

I think I've found the issue. The plugin was calling openShops.remove(p) while iterating the objects synchronized, which of course will throw an exception.

Removing the object from the iterator seems to solve the problem (it.remove()).

I'll file an alpha release, lets see if this will fix your issues.

2.2.1-alpha

kotarobo commented 4 years ago

I've tested it and the server no longer crashes! I think the problem has been solved. Thank you!