GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix a `Bytebuf` leak in `TcpDnsQueryDecoder` by ikhoon · Pull Request #15033 · netty/netty

Conversation

@ikhoon

@ikhoon ikhoon commented Apr 15, 2025

Copy link
Copy Markdown
Contributor

Motivation:

A memory leak was detected during the implementation of a DNS over TCP server.

15:49:44.002 [armeria-common-worker-kqueue-2-6] ERROR io.netty.util.ResourceLeakDetector - 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:
  io.netty.buffer.AdvancedLeakAwareByteBuf.readUnsignedShort(AdvancedLeakAwareByteBuf.java:419)
  io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeQuestion(DefaultDnsRecordDecoder.java:38)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeQuestions(DnsMessageUtil.java:221)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeDnsQuery(DnsMessageUtil.java:192)
  io.netty.handler.codec.dns.TcpDnsQueryDecoder.decode(TcpDnsQueryDecoder.java:48)
  io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:333)
  io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
  io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
  io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
  io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)

It seems that the frame generated by LengthFieldBasedFrameDecoder.decode() TcpDnsQueryDecoder is not released after being decoded by TcpDnsQueryDecoder.

netty/codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java

Lines 42 to 53 in d639d87

protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
ByteBuf frame = (ByteBuf) super.decode(ctx, in);
if (frame == null) {
return null;
}
return DnsMessageUtil.decodeDnsQuery(decoder, frame.slice(), new DnsMessageUtil.DnsQueryFactory() {
@Override
public DnsQuery newQuery(int id, DnsOpCode dnsOpCode) {
return new DefaultDnsQuery(id, dnsOpCode);
}
});

Motifications:

  • Release frame after use.

Result:

Resolved a memory leak in TcpDnsQueryEncoder

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ikhoon
Fix a Bytebuf leak in TcpDnsQueryDecoder
2902f68
Motivation:

A memory leak was detected during the implementation of a DNS over TCP server.
```
15:49:44.002 [armeria-common-worker-kqueue-2-6] ERROR io.netty.util.ResourceLeakDetector - 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:
  io.netty.buffer.AdvancedLeakAwareByteBuf.readUnsignedShort(AdvancedLeakAwareByteBuf.java:419)
  io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeQuestion(DefaultDnsRecordDecoder.java:38)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeQuestions(DnsMessageUtil.java:221)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeDnsQuery(DnsMessageUtil.java:192)
  io.netty.handler.codec.dns.TcpDnsQueryDecoder.decode(TcpDnsQueryDecoder.java:48)
  io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:333)
  io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
  io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
  io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
  io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
```

It seems that the `frame` generated by `LengthFieldBasedFrameDecoder.decode()`
`TcpDnsQueryDecoder` is not released after being decoded by `TcpDnsQueryDecoder`.
https://github.com/netty/netty/blob/d639d876aa577eea21acebaa970c8cc60644a851/codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java#L42-L53

Motifications:

- Release `frame` after use.

Result:

Resolved a memory leak in `TcpDnsQueryEncoder`
ikhoon added a commit to ikhoon/armeria that referenced this pull request Apr 15, 2025
@ikhoon
Fix a memory leak in DnsOverTcpTest
2ed6a1e
Motivation:

A memory leak was detected while running `DnsOverTcpTest`.
Related: netty/netty#15033

Modifications:

- Forked `TcpDnsQueryDecoder` and applied a patch to fix the memory leak.

Result:

Stabilize CI builds
@ikhoon ikhoon mentioned this pull request Apr 15, 2025
Fix a memory leak in DnsOverTcpTest line/armeria#6206
Merged
@normanmaurer

normanmaurer commented Apr 15, 2025

Copy link
Copy Markdown
Member

@ikhoon great catch!

ikhoon reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer normanmaurer added this to the 4.2.1.Final milestone Apr 15, 2025
@normanmaurer
normanmaurer merged commit a9f5840 into netty:4.2 Apr 15, 2025
normanmaurer pushed a commit that referenced this pull request Apr 15, 2025
@ikhoon @normanmaurer
Fix a Bytebuf leak in TcpDnsQueryDecoder (#15033)
8d0d56b
Motivation:

A memory leak was detected during the implementation of a DNS over TCP
server.
```
15:49:44.002 [armeria-common-worker-kqueue-2-6] ERROR io.netty.util.ResourceLeakDetector - 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:
  io.netty.buffer.AdvancedLeakAwareByteBuf.readUnsignedShort(AdvancedLeakAwareByteBuf.java:419)
  io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeQuestion(DefaultDnsRecordDecoder.java:38)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeQuestions(DnsMessageUtil.java:221)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeDnsQuery(DnsMessageUtil.java:192)
  io.netty.handler.codec.dns.TcpDnsQueryDecoder.decode(TcpDnsQueryDecoder.java:48)
  io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:333)
  io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
  io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
  io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
  io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
```

It seems that the `frame` generated by
`LengthFieldBasedFrameDecoder.decode()` `TcpDnsQueryDecoder` is not
released after being decoded by `TcpDnsQueryDecoder`.
https://github.com/netty/netty/blob/d639d876aa577eea21acebaa970c8cc60644a851/codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java#L42-L53

Motifications:

- Release `frame` after use.

Result:

Resolved a memory leak in `TcpDnsQueryEncoder`
normanmaurer added a commit that referenced this pull request Apr 15, 2025
@normanmaurer @ikhoon
Fix a Bytebuf leak in TcpDnsQueryDecoder (#15033) (#15035)
4adb523
Motivation:

A memory leak was detected during the implementation of a DNS over TCP
server.
```
15:49:44.002 [armeria-common-worker-kqueue-2-6] ERROR io.netty.util.ResourceLeakDetector - 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:
  io.netty.buffer.AdvancedLeakAwareByteBuf.readUnsignedShort(AdvancedLeakAwareByteBuf.java:419)
  io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeQuestion(DefaultDnsRecordDecoder.java:38)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeQuestions(DnsMessageUtil.java:221)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeDnsQuery(DnsMessageUtil.java:192)
  io.netty.handler.codec.dns.TcpDnsQueryDecoder.decode(TcpDnsQueryDecoder.java:48)
  io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:333)
  io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
  io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
  io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
  io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
```

It seems that the `frame` generated by
`LengthFieldBasedFrameDecoder.decode()` `TcpDnsQueryDecoder` is not
released after being decoded by `TcpDnsQueryDecoder`.
https://github.com/netty/netty/blob/d639d876aa577eea21acebaa970c8cc60644a851/codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java#L42-L53

Motifications:

- Release `frame` after use.

Result:

Resolved a memory leak in `TcpDnsQueryEncoder`

Co-authored-by: Ikhun Um <[email protected]>
normanmaurer added a commit that referenced this pull request Apr 15, 2025
@normanmaurer @ikhoon
Fix a Bytebuf leak in TcpDnsQueryDecoder (#15033) (#15035)
c64fcac
Motivation:

A memory leak was detected during the implementation of a DNS over TCP
server.
```
15:49:44.002 [armeria-common-worker-kqueue-2-6] ERROR io.netty.util.ResourceLeakDetector - 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:
  io.netty.buffer.AdvancedLeakAwareByteBuf.readUnsignedShort(AdvancedLeakAwareByteBuf.java:419)
  io.netty.handler.codec.dns.DefaultDnsRecordDecoder.decodeQuestion(DefaultDnsRecordDecoder.java:38)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeQuestions(DnsMessageUtil.java:221)
  io.netty.handler.codec.dns.DnsMessageUtil.decodeDnsQuery(DnsMessageUtil.java:192)
  io.netty.handler.codec.dns.TcpDnsQueryDecoder.decode(TcpDnsQueryDecoder.java:48)
  io.netty.handler.codec.LengthFieldBasedFrameDecoder.decode(LengthFieldBasedFrameDecoder.java:333)
  io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
  io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
  io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
  io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
```

It seems that the `frame` generated by
`LengthFieldBasedFrameDecoder.decode()` `TcpDnsQueryDecoder` is not
released after being decoded by `TcpDnsQueryDecoder`.
https://github.com/netty/netty/blob/d639d876aa577eea21acebaa970c8cc60644a851/codec-dns/src/main/java/io/netty/handler/codec/dns/TcpDnsQueryDecoder.java#L42-L53

Motifications:

- Release `frame` after use.

Result:

Resolved a memory leak in `TcpDnsQueryEncoder`

Co-authored-by: Ikhun Um <[email protected]>
@ikhoon
ikhoon deleted the fix-tcp-query-decoder-leak branch April 16, 2025 01:19
ikhoon added a commit to line/armeria that referenced this pull request Apr 17, 2025
@ikhoon
Fix a memory leak in DnsOverTcpTest (#6206)
3a35abe
Motivation:

A memory leak was detected while running `DnsOverTcpTest`. Related:
netty/netty#15033

Modifications:

- Forked `TcpDnsQueryDecoder` and applied a patch to fix the memory
leak.

Result:

Stabilize CI builds
This was referenced Sep 14, 2026
Http2: Reserve promised stream for PUSH_PROMISE after local RST_STREAM #17471
Closed
cache failure 1233e4a5 #17565
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.2.1.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ikhoon @normanmaurer
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.