Merge branch 'fix/netty-illegalreferencecount' into 'dev'

Fixes issue #588, netty IllegalReferenceCount

See merge request morningstar/Arcturus-Community!136
This commit is contained in:
Harmonic 2020-05-03 10:13:06 -04:00
commit fe533a17c9
5 changed files with 47 additions and 8 deletions

View File

@ -89,7 +89,7 @@ public class GameClient {
public void sendResponse(MessageComposer composer) { public void sendResponse(MessageComposer composer) {
if (this.channel.isOpen()) { if (this.channel.isOpen()) {
try { try {
this.channel.write(composer.compose(), this.channel.voidPromise()); this.channel.write(composer.compose().retain(), this.channel.voidPromise());
this.channel.flush(); this.channel.flush();
} catch (Exception e) { } catch (Exception e) {
Emulator.getLogging().logPacketError(e); Emulator.getLogging().logPacketError(e);
@ -103,7 +103,7 @@ public class GameClient {
return; return;
} }
this.channel.write(response, this.channel.voidPromise()); this.channel.write(response.retain(), this.channel.voidPromise());
this.channel.flush(); this.channel.flush();
} }
} }
@ -115,7 +115,7 @@ public class GameClient {
return; return;
} }
this.channel.write(response); this.channel.write(response.retain());
} }
this.channel.flush(); this.channel.flush();

View File

@ -4,11 +4,14 @@ import com.eu.habbo.Emulator;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream; import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import io.netty.util.IllegalReferenceCountException;
import io.netty.util.ReferenceCounted;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.Charset; import java.nio.charset.Charset;
public class ServerMessage { public class ServerMessage implements ReferenceCounted {
private int header; private int header;
private ByteBufOutputStream stream; private ByteBufOutputStream stream;
private ByteBuf channelBuffer; private ByteBuf channelBuffer;
@ -192,8 +195,42 @@ public class ServerMessage {
return this.channelBuffer.copy(); return this.channelBuffer.copy();
} }
public void release() { @Override
this.channelBuffer.release(); public int refCnt() {
return this.channelBuffer.refCnt();
}
@Override
public ReferenceCounted retain() {
this.channelBuffer.retain();
return this;
}
@Override
public ReferenceCounted retain(int i) {
this.channelBuffer.retain(i);
return this;
}
@Override
public ReferenceCounted touch() {
this.channelBuffer.touch();
return this;
}
@Override
public ReferenceCounted touch(Object o) {
this.channelBuffer.touch(o);
return this;
}
public boolean release() {
return this.channelBuffer.release();
}
@Override
public boolean release(int i) {
return this.channelBuffer.release(i);
} }
} }

View File

@ -54,6 +54,8 @@ public class GameMessageHandler extends ChannelInboundHandlerAdapter {
if (cause instanceof TooLongFrameException) { if (cause instanceof TooLongFrameException) {
Emulator.getLogging().logErrorLine("Disconnecting client, reason: \"" + cause.getMessage() + "\"."); Emulator.getLogging().logErrorLine("Disconnecting client, reason: \"" + cause.getMessage() + "\".");
} else { } else {
cause.printStackTrace();
Emulator.getLogging().logErrorLine("Disconnecting client, exception in GameMessageHander:"); Emulator.getLogging().logErrorLine("Disconnecting client, exception in GameMessageHander:");
Emulator.getLogging().logErrorLine(cause.toString()); Emulator.getLogging().logErrorLine(cause.toString());

View File

@ -14,7 +14,7 @@ public class GameServerMessageLogger extends MessageToMessageEncoder<ServerMessa
protected void encode(ChannelHandlerContext ctx, ServerMessage message, List<Object> out) throws Exception { protected void encode(ChannelHandlerContext ctx, ServerMessage message, List<Object> out) throws Exception {
Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + message.getHeader() + "] -> " + message.getBodyString()); Emulator.getLogging().logPacketLine("[" + Logging.ANSI_PURPLE + "SERVER" + Logging.ANSI_RESET + "] => [" + message.getHeader() + "] -> " + message.getBodyString());
out.add(message); out.add(message.retain());
} }
} }

View File

@ -4,6 +4,7 @@ import com.eu.habbo.messages.ServerMessage;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import io.netty.util.IllegalReferenceCountException;
public class ServerMessageEncoder extends MessageToByteEncoder<ServerMessage> { public class ServerMessageEncoder extends MessageToByteEncoder<ServerMessage> {
@ -15,7 +16,6 @@ public class ServerMessageEncoder extends MessageToByteEncoder<ServerMessage> {
out.writeBytes(buf); out.writeBytes(buf);
} finally { } finally {
buf.release(); buf.release();
message.release();
} }
} }