-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Assert Not Escaping byte[] from Pooled ByteBuf #44881
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
Assert Not Escaping byte[] from Pooled ByteBuf #44881
Conversation
Pinging @elastic/es-distributed |
Jenkins run elasticsearch-ci/packaging-sample |
Jenkins run elasticsearch-ci/1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@original-brownbear I want to better understand why you propose to add assertion here.
Do I understand correctly that currently we never use pooled byte buffers, that are wrapped with ByteBufferByteReference and you want to prevent this in the future?
We do use I'd like to prevent us from doing that in the future because it could lead to some severe and hard to track down bugs. Those would happen if we would create the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have created ByteBufBytesReference from the pooled ByteBuf and you have released pooled ByteBuf, you can no longer work with ByteBufBytesReference methods, such as get
, indexOf
, etc.
So you kind of expect that you should never release ByteBuf until ByteBufBytesReference goes out of scope.
If you call toBytesRef method you also expect that you should not release ByteBuf until returned BytesRef goes out of scope.
Probably we should just add this kind of docs to ByteBufBytesReference class.
I mean the assertion that you propose to add does not make ByteBufBytesReference class completely safe, but additionally, it restricts this class unsafe usage.
If documentation is not enough from your point of view, I suggest to 2 separate classes SafeByteBufBytesReference and UnsafeByteBufBytesReference, the first one will check that passed in ByteBuf is unpooled during construction.
I would argue in tests it will recognize any unsafe usage?
What does that get us? We are creating these instances on the network layer and passing them down to transport handlers. We need to ensure that transport handlers don't do the wrong thing on pooled buffers and start to create unsafe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
#44564 makes this assertion wrong, we are now conciously escaping these bytes at times. |
BytesRef
after releasing the wrappedByteBuf
ByteBuf
there because the derivedBytesRef
from it would contain garbage if they were to live beyond releasing theByteBuf
, shouldn't we then prevent this (using the array from a pooled buffer to back aBytesRef
from ever happening?