Repository navigation
ReadOnlyByteBuf (and sub-classes) does not create derived buffers tha… - #14076
Conversation
…t share reference count Motivation: The derived buffers that are created via ReadOnlyByteBuf (and sub-classes) do not share the reference count with the parent. This results in buffer leaks Modifications: - Correctly share reference count - Add unit tests Result: Fix #14075
lhotari
left a comment
There was a problem hiding this comment.
Looks great! Thanks for addressing this so quickly.
| public boolean isWritable(int numBytes) { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
In addition to the above methods, nioBuffer and nioBuffers methods should return read-only ByteBuffer instances. While looking into this I noticed that the override for nioBuffer exists in ReadOnlyByteBufferBuf, but the nioBuffers override is missing.
Something like this for making nioBuffer and nioBuffers return read-only ByteBuffers?
@Override
public ByteBuffer nioBuffer(int index, int length) {
return unwrap().nioBuffer(index, length).asReadOnlyBuffer();
}
@Override
public ByteBuffer[] nioBuffers(int index, int length) {
ByteBuffer[] byteBuffers = unwrap().nioBuffers(index, length);
for (int i = 0; i < byteBuffers.length; i++) {
byteBuffers[i] = byteBuffers[i].asReadOnlyBuffer();
}
return byteBuffers;
}There was a problem hiding this comment.
The reason why read-only ByteBuffers are needed in the SslHandler use case is to avoid mutating the buffer. JDK's SSLEngine will mutate the input buffer with an in-place encryption reusing the input buffer unless the buffer is read-only. The support for read-only ByteBuffers in JDK's SSLEngine was added as a result of a bug reported by @chrisvest, more details in comment #14069 (comment) .
…t share reference count
Motivation:
The derived buffers that are created via ReadOnlyByteBuf (and sub-classes) do not share the reference count with the parent. This results in buffer leaks
Modifications:
Result:
Fix #14075