问题描述:
this4j-->ERROR {ResourceLeakDetector.java:319} - LEAK: ByteBuf.release() was not called before it's garbage-collected. See https://netty.io/wiki/reference-counted-objects.html for more information.
Recent access records:
#1:
io.netty.buffer.AdvancedLeakAwareByteBuf.copy(AdvancedLeakAwareByteBuf.java:700)
io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBodyAttributesStandard(HttpPostStandardRequestDecoder.java:463)
io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBodyAttributes(HttpPostStandardRequestDecoder.java:505)
io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.parseBody(HttpPostStandardRequestDecoder.java:360)
io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.offer(HttpPostStandardRequestDecoder.java:289)
io.netty.handler.codec.http.multipart.HttpPostStandardRequestDecoder.<init>(HttpPostStandardRequestDecoder.java:154)
io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.<init>(HttpPostRequestDecoder.java:99)
io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.<init>(HttpPostRequestDecoder.java:68)
*********.websocket.netty.NettyHttpServletRequest.<init>(NettyHttpServletRequest.java:42)
排查定位到异常代码:发现每次都是 new decoder的地方报错,查了诸多ByteBuf释放,发现decoder也需要释放,语是补上了绿色部分代码,问题ok
HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(
new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE), request);
try {
List<InterfaceHttpData> postDatas = decoder.getBodyHttpDatas();
if (postDatas != null && postDatas.size() > 0) {
for (InterfaceHttpData postData : postDatas) {
if (postData != null) {
if (postData.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
Attribute attribute = (Attribute) postData;
params.put(attribute.getName(), attribute.getValue());
}
}
}
}
} catch (Exception e) {
LogUtil.e("NettyHttpServletRequest err", e);
} finally {
ReferenceCountUtil.safeRelease(request);
decoder.destroy();
}
感谢文章:
https://blog.csdn.net/hannuotayouxi/article/details/78827499