question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Proposal] Keep information about the class/method that released the buffer

See original GitHub issue

From time to time you get this notorious IllegalReferenceCountException which basically means that you released the same buffer twice.

It can be a real pain in the neck to track down the method which released this particular buffer. It’s especially painful if you have a quite large pipeline and you’re juggling with ByteBuf instances back and forth.

The exception itself tells only two things:

  1. The buffer was already released (i.e. its reference counter is zero)
  2. The actual stack trace which shows you which method and in which class called the ByteBuf::release method

It would be great if Netty could keep some information about the caller in the ByteBuf instances. So when you call the ByteBuf::release method and see that the reference counter is zero, you could attach this information to the exception message and a user would know who released this particular buffer earlier.

I think it would simplify the debugging process a little bit. At the moment it can often be impossible to understand who released the buffer without knowing this additional information about the previous caller.

Reflection.getCallerClass() or something similar should do the trick. This feature can also be implemented as a special type of ByteBuf which can only be enabled with some startup option (like a memory leak detector). Because it’ll definitely be very costly to use this feature all the time, I think.

WDYT?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Scottmitchcommented, May 23, 2017

This request sounds different than io.netty.util.ResourceLeakDetector. Instead of detecting things that aren’t released (what io.netty.util.ResourceLeakDetector tries to do) this is requesting tracking call stack information when a buffer is actually released to help debug “double release” scenarios.

As you indicated I think the challenge here is balancing overhead introduced by the additional tracking and potential API impacts. Do we retain a field in each object and increase the memory footprint of each object (even if we are not “tracking” would we still have an additional member variable to track)? Do we sample like we do for ref counting … what if your object wasn’t sampled do we offer a mode to track all deallocations? How common is this in practice and is it worth the additional work/overhead to track this?

0reactions
maseevcommented, Sep 18, 2017

On second thought, I think it would be a good idea to share this feature. I’ll create a PR soon.

Read more comments on GitHub >

github_iconTop Results From Across the Web

chain of command - accessing buffer from the base class...
Hi Guys,. Sorry for the novoice question, but I often get confused while doing COC. ... should i declare and initialize purchPurchaseOrderHeader ...
Read more >
How to copy and release a buffer in Gstreamer - Stack Overflow
I am working with Deepstream. If I access the copied buffer after a few seconds the data in the buffer is not the...
Read more >
SAP ABAP Class CL_RSPLS_PLAN_BUFFER (Plan Buffer)
Sets the buffer (for documentation?) 20120618. 17, _GET_DATA_READ_OPTION, Instance method · Private · Method, Defines the reader method for reading DATA ...
Read more >
node_modules/safe-buffer ... - Git ECE IASTATE
Class Method : Buffer.from(arrayBuffer[, byteOffset[, length]]) ... copy the data into the new allocation data.copy(sb, 0, 0, 10); store.push(sb); });.
Read more >
PEP 3137 – Immutable Bytes and Mutable Buffer
After releasing Python 3.0a1 with a mutable bytes type, pressure mounted to add a way to represent immutable bytes. Gregory P. Smith proposed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found