Fix race condition

This commit is contained in:
Eoghanmc22 2020-11-25 11:28:37 -05:00
parent d056fceb8a
commit d1138f9f81
4 changed files with 18 additions and 6 deletions

@ -1 +1 @@
Subproject commit 33abb2dc5dd350f05c8efbeb80835edf01056ff2
Subproject commit 843fc32877802b9b86ae291a2b2fa3d633c24183

View File

@ -23,6 +23,8 @@ import net.minestom.server.network.PacketProcessor;
import net.minestom.server.network.netty.channel.ClientChannel;
import net.minestom.server.network.netty.codec.*;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
@ -33,6 +35,8 @@ public final class NettyServer {
private static final long DEFAULT_COMPRESSED_CHANNEL_WRITE_LIMIT = 600_000L;
private static final long DEFAULT_COMPRESSED_CHANNEL_READ_LIMIT = 100_000L;
private static final Logger log = LoggerFactory.getLogger(NettyServer.class);
private static final long DEFAULT_UNCOMPRESSED_CHANNEL_WRITE_LIMIT = 15_000_000L;
private static final long DEFAULT_UNCOMPRESSED_CHANNEL_READ_LIMIT = 1_000_000L;
@ -74,21 +78,29 @@ public final class NettyServer {
worker = new IOUringEventLoopGroup(); // thread count = core * 2
channel = IOUringServerSocketChannel.class;
log.info("Using Io_uring");
} else if (Epoll.isAvailable()) {
boss = new EpollEventLoopGroup(2);
worker = new EpollEventLoopGroup(); // thread count = core * 2
channel = EpollServerSocketChannel.class;
log.info("Using Epoll");
} else if (KQueue.isAvailable()) {
boss = new KQueueEventLoopGroup(2);
worker = new KQueueEventLoopGroup(); // thread count = core * 2
channel = KQueueServerSocketChannel.class;
log.info("Using KQueue");
} else {
boss = new NioEventLoopGroup(2);
worker = new NioEventLoopGroup(); // thread count = core * 2
channel = NioServerSocketChannel.class;
log.info("Using Nio");
}
bootstrap = new ServerBootstrap()

View File

@ -63,12 +63,13 @@ public class TemporaryCache<T> {
*/
@Nullable
public synchronized T retrieve(@NotNull UUID identifier, long lastUpdate) {
if (!cacheTime.containsKey(identifier)) {
Long tempL = cacheTime.get(identifier);
if (tempL == null) {
return null;
}
final long cachedTime = cacheTime.get(identifier);
return lastUpdate <= cachedTime ? cache.get(identifier) : null;
//cache.get(identifier) will return null if the race condition occurred which is what we want
return lastUpdate <= tempL ? cache.get(identifier) : null;
}
/**

View File

@ -19,8 +19,7 @@ public class PlayersCommand extends Command {
private void usage(CommandSender sender, Arguments arguments) {
final Collection<Player> players = MinecraftServer.getConnectionManager().getOnlinePlayers();
final int playerCount = players.size();
sender.sendMessage(String.valueOf(playerCount));
sender.sendMessage("");
sender.sendMessage("Total players: " + playerCount);
final int limit = 15;
if (playerCount <= limit) {
for (final Player player : players) {