Skip to content

Avoid allocating ByteBuf's on non-SDK threads #1133

Closed
@dagnir

Description

@dagnir

Expected Behavior

We use the default PooledByteBufAllocator in Netty which creates per-thread caches stored in a ThreadLocal. To avoid polluting threads we don't own, we should ensureByteBufs allocated by the Netty client are allocated only on SDK threads.

Current Behavior

It's possible for the Netty client to allocate within a customer's thread, for example, in the onNext of an SDK Subscriber with a subscription to a customer provided Publisher:

public void onNext(ByteBuffer byteBuffer) {
if (done) {
return;
}
try {
int newLimit = clampedBufferLimit(byteBuffer.remaining());
byteBuffer.limit(newLimit);
ByteBuf buffer = channel.alloc().buffer(byteBuffer.remaining());
buffer.writeBytes(byteBuffer);
HttpContent content = new DefaultHttpContent(buffer);

Possible Solution

The easiest solution would be to allocate using io.netty.buffer.Unpooled. Otherwise, we should defer the allocation and run it in the EventLoop.

Steps to Reproduce (for bugs)

Context

Your Environment

  • AWS Java SDK version used: 2.5.10
  • JDK version used:
  • Operating System and version:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions