Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release netty ByteBuf after use #2835

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public void process(CommandProcess process) {
}

InputStream input = null;
ByteBuf convertResult = null;

try {
input = new FileInputStream(f);
byte[] bytes = IOUtils.getBytes(input);

ByteBuf convertResult = null;
if (this.decode) {
convertResult = Base64.decode(Unpooled.wrappedBuffer(bytes));
} else {
Expand All @@ -138,6 +138,9 @@ public void process(CommandProcess process) {
process.end(1, "read file error: " + e.getMessage());
return;
} finally {
if (convertResult != null) {
convertResult.release();
}
IOUtils.close(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,25 @@ public void channelRead0(ChannelHandlerContext ctx, HttpObject msg) {
if (msg instanceof HttpContent) {
HttpContent content = (HttpContent) msg;

ByteBuf byteBuf = content.content();
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);
ByteBuf byteBuf = null;
try{
byteBuf = content.content();
byte[] bytes = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(bytes);

simpleHttpResponse.setContent(bytes);
simpleHttpResponse.setContent(bytes);

promise.setSuccess(simpleHttpResponse);
promise.setSuccess(simpleHttpResponse);

if (content instanceof LastHttpContent) {
ctx.close();
if (content instanceof LastHttpContent) {
ctx.close();
}
}finally {
if (byteBuf != null) {
byteBuf.release();
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,24 @@ public void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws
String targetUrl = targetUrls.get(0);
SimpleHttpResponse simpleHttpResponse = proxyClient.query(targetUrl);

ByteBuf byteBuf = Base64
.encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse)));
String requestData = byteBuf.toString(CharsetUtil.UTF_8);

QueryStringEncoder queryEncoder = new QueryStringEncoder("");
queryEncoder.addParam(URIConstans.METHOD, MethodConstants.HTTP_PROXY);
queryEncoder.addParam(URIConstans.PROXY_REQUEST_ID, id);
queryEncoder.addParam(URIConstans.PROXY_RESPONSE_DATA, requestData);

String url = queryEncoder.toString();
ctx.writeAndFlush(new TextWebSocketFrame(url));
ByteBuf byteBuf = null;
try{
byteBuf = Base64
.encode(Unpooled.wrappedBuffer(SimpleHttpResponse.toBytes(simpleHttpResponse)));
String requestData = byteBuf.toString(CharsetUtil.UTF_8);

QueryStringEncoder queryEncoder = new QueryStringEncoder("");
queryEncoder.addParam(URIConstans.METHOD, MethodConstants.HTTP_PROXY);
queryEncoder.addParam(URIConstans.PROXY_REQUEST_ID, id);
queryEncoder.addParam(URIConstans.PROXY_RESPONSE_DATA, requestData);

String url = queryEncoder.toString();
ctx.writeAndFlush(new TextWebSocketFrame(url));
}finally {
if (byteBuf != null) {
byteBuf.release();
}
}
}
}

Expand Down
Loading