Skip to content

Commit

Permalink
fix IllegalReferenceCountException
Browse files Browse the repository at this point in the history
  • Loading branch information
danthe1st committed Mar 9, 2024
1 parent 6ba4e5e commit 0a00b0a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ public String getAsString() {
private void ensureBytesPresent() {
if(bytes == null){
ByteBuf buf = contentBuf.copy();
bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
try{
bytes = new byte[buf.readableBytes()];
buf.readBytes(bytes);
}finally{
buf.release();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.ssl.SniHandler;
import io.netty.handler.ssl.SslContext;
import io.netty.util.IllegalReferenceCountException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -76,7 +75,7 @@ private void forwardRequest(ChannelHandlerContext channelHandlerContext, FullHtt
Channel outChannel = actualClientBootstrap.connect(hostname, 443)
.sync()
.channel();

fullHttpRequest.retain();
outChannel.writeAndFlush(fullHttpRequest).sync();
}catch(InterruptedException e){
throw e;
Expand All @@ -91,13 +90,11 @@ private void forwardRequest(ChannelHandlerContext channelHandlerContext, FullHtt
// the client receives a 502 Bad Gateway response including the stack trace
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
if(!(cause instanceof IllegalReferenceCountException)){
LOG
.atError()
.addArgument(sniHandler::hostname)
.log("An exception occured trying to process a request to host '{}'", cause);
ctx.channel().close();
}
}

private void writeException(Throwable cause, Channel channel) throws InterruptedException, IOException {
Expand Down

0 comments on commit 0a00b0a

Please sign in to comment.