diff --git a/fml/src/main/java/cpw/mods/fml/common/network/internal/FMLProxyPacket.java b/fml/src/main/java/cpw/mods/fml/common/network/internal/FMLProxyPacket.java index 7726a615d..e8f16257f 100644 --- a/fml/src/main/java/cpw/mods/fml/common/network/internal/FMLProxyPacket.java +++ b/fml/src/main/java/cpw/mods/fml/common/network/internal/FMLProxyPacket.java @@ -11,8 +11,12 @@ import net.minecraft.network.PacketBuffer; import net.minecraft.network.play.client.C17PacketCustomPayload; import net.minecraft.network.play.server.S3FPacketCustomPayload; import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.helpers.Integers; +import com.google.common.collect.ConcurrentHashMultiset; +import com.google.common.collect.Multiset; +import com.google.common.collect.Multiset.Entry; +import com.google.common.collect.Multisets; import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.FMLNetworkException; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.network.handshake.NetworkDispatcher; @@ -24,7 +28,8 @@ public class FMLProxyPacket extends Packet { private final ByteBuf payload; private INetHandler netHandler; private NetworkDispatcher dispatcher; - + private static Multiset badPackets = ConcurrentHashMultiset.create(); + private static int packetCountWarning = Integers.parseInt(System.getProperty("fml.badPacketCounter", "100"), 100); private FMLProxyPacket(byte[] payload, String channel) { this(Unpooled.wrappedBuffer(payload), channel); @@ -71,7 +76,17 @@ public class FMLProxyPacket extends Packet { { if (internalChannel.writeInbound(this)) { - FMLLog.severe("Messages for channel %s for side %s were not processed by the embedded channel %s.\n They have been dropped.\n%s", this.channel, this.target, internalChannel.inboundMessages(), ByteBufUtils.getContentDump(this.payload)); + badPackets.add(this.channel); + if (badPackets.size() % packetCountWarning == 0) + { + FMLLog.severe("Detected ongoing potential memory leak. %d packets have leaked. Top offenders", badPackets.size()); + int i = 0; + for (Entry s : Multisets.copyHighestCountFirst(badPackets).entrySet()) + { + if (i++ > 10) break; + FMLLog.severe("\t %s : %d", s.getElement(), s.getCount()); + } + } } internalChannel.inboundMessages().clear(); }